Skip to content
Advertisement

Tag: jestjs

How to mock nanoid for testing?

I’m trying to mock nanoid for my testing but it doesn’t seem to be working. my function My test: So basically I’m struggling to figure out how to mock the nanoid which is generated inside the function. I’ve tried the following at the top of the file: however it doesn’t work at all. Any help would be appreciated! Answer You

Using jest with files with glob imports

I utilize webpack with webpack-import-glob-loader to import files using glob pattern. So in one of my files (src/store/resources/module.ts) I have a line: When I run a test with ts-jest it fails and reports the following message: Cannot find module ‘../../modules/resources/providers/**/*.resource.ts’ from ‘src/store/resources/module.ts` I assume it complains because it can’t recognize this import syntax. How to make jest work for project

Jest with vanilla JS – tesing generated elements on DOM

Searched a lot online but cant find the best way to get an element’s innerHTML and just compare it with the results that should be rendered (I’m trying to compare with string) what I’m trying is adding some whitespace and test failed so I’m guessing there is better ways Also, unable to query a specific element generated inside body, why?

Advertisement