21
loading...
This website collects cookies to deliver better user experience
html-maker
so as to test it outmodule.exports.processingFile = processingFile;
module.exports.processMarkdown = processMarkdown;
npm i -D jest
npm i -D ts-jest @types/jest
npx ts-jest config:init
jest.config.js
will give you an option to customize Jest. But when I was writting test using Jest. Eslint always warn me about describe
and it
or test
is not defined and that is because Typescript is not know about these exposed objects yet so I need to add a few change in my .eslintrc.json
to tunr off those warnings from Eslint"env": {
"browser": true,
"es2021": true,
"node": true,
"jest/globals": true
},
html-maker
to see if I have the right output for the markdown and whether if it will return a blank string if I inpout the wrong file typeconst { processingFile, processMarkdown } = require('../html-maker');
describe('testing HTML generator', () => {
it('should return blank with invalid file extension', () => {
const fileName = 'test.dat';
expect(processingFile(fileName)).toEqual('');
});``
it('should return correct markdown for mock content', () => {
const mockData = '## Testing testing';
expect(processMarkdown(mockData)).toMatch('<h2>Testing testing</h2>');
});
});
toEqual(string)
but when I check how they would test a string. It turn out that I need to use toMatch(string)