mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
feat(jest): mithril component testing (#3679)
* feat(jest): create jest config package for unit testing * chore: housekeeping * fix: now we need to explicitly allow importing without extension * fix: recover EditorDriverInterface import * feat(jest): mithril component testing * fix: use separate `tsconfig.test.json` Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
21
js-packages/jest-config/test-matchers.ts
Normal file
21
js-packages/jest-config/test-matchers.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { expect } from '@jest/globals';
|
||||
|
||||
// Extend Jest with mithril component test matchers.
|
||||
expect.extend({
|
||||
toHaveElement: intoMatcher((out: any, expected: any) => out.should.have(expected), 'Expected $received to have node $expected'),
|
||||
toContainRaw: intoMatcher((out: any, expected: any) => out.should.contain(expected), 'Expected $received to contain $expected'),
|
||||
});
|
||||
|
||||
function intoMatcher(callback: Function, message: string) {
|
||||
return function (this: any, received: any, ...expected: any) {
|
||||
try {
|
||||
callback(received, ...expected);
|
||||
return { pass: true, message: () => '' };
|
||||
} catch (e) {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => message.replace('$expected', this.utils.printExpected(expected)).replace('$received', this.utils.printReceived('component')),
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user