1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 01:16:52 +02:00

test: add frontend tests (#3991)

This commit is contained in:
Sami Mazouz
2024-09-28 15:47:45 +01:00
committed by GitHub
parent c0d3d976fa
commit 257be2b9db
90 changed files with 4581 additions and 3167 deletions

View File

@@ -4,6 +4,19 @@ import { expect } from '@jest/globals';
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'),
toHaveElementAttr: intoMatcher(function (out: any, selector: string, attribute: string, value: string | undefined) {
out.should.have(selector);
const node = out.find(selector)[0];
const attr = node[attribute] ?? node._attrsByQName[attribute]?.data ?? undefined;
const onlyTwoArgs = value === undefined;
if (!node || (!onlyTwoArgs && attr !== value) || (onlyTwoArgs && !attr)) {
throw new Error(`Expected ${selector} to have attribute ${attribute} with value ${value}, but found ${node[attribute]}`);
}
}, 'Expected $received to have attribute $expected with value $value'),
});
function intoMatcher(callback: Function, message: string) {