我创建了一个自定义茉莉花匹配器:
export class OwnMatchers implements jasmine.CustomMatcherFactories {
[index: string]: any;
public toCheck(util: jasmine.MatchersUtil, customEqualityTesters: Array<jasmine.CustomEqualityTester>) {
return {
compare: async function (actual:any, expected: any) {
if (expected === undefined) {
expected = '';
}
const result = <jasmine.CustomMatcherResult>{};
let resultTest = await SreenShotTest.Check(expected.Data);
result.pass = util.equals(resultTest, true, customEqualityTesters);
if (result.pass)
{result.message = "Success" + ' ' + expected.Data;}
else
{result.message = "Not Success" + ' ' + expected.Data;}
return result;
}
}
}
}
我用那个
const customOwnMatchers = new OwnMatchers();
describe('App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
jasmine.addMatchers(customOwnMatchers);
});
it('Test 1', async() => {
...
...
await (<any>expect()).toCheck({Data: '1'});
});
});
运行测试(ng e2e)后,我收到此错误消息:
预期为undefined以检查Object({Data:'1'})。
谢谢您的回答