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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user