jasmine-matchers

How to let know typescript compiler about jest custom matchers?

懵懂的女人 提交于 2020-02-24 03:43:08
问题 I have a react/typescript project, using jest, where I have a custom matcher like: export const MyCustomMatchers = { toBeTheSameAsRemote: function(_util: any, _customEqualityTesters: any) { return { compare: function(actual: Brand, expected: RemoteBrand) { const pass: boolean = attributesMatch(actual, expected); const message: string = pass ? 'Local matches Remote' : 'Local does not match Remote'; return { pass, message: () => message }; } }; } }; which I reference in my tests by doing inside

toBe(true) vs toBeTruthy() vs toBeTrue()

浪子不回头ぞ 提交于 2020-01-22 04:04:47
问题 What is the difference between expect(something).toBe(true) , expect(something).toBeTruthy() and expect(something).toBeTrue() ? Note that toBeTrue() is a custom matcher introduced in jasmine-matchers among other useful and handy matchers like toHaveMethod() or toBeArrayOfStrings() . The question is meant to be generic, but, as a real-world example, I'm testing that an element is displayed in protractor . Which matcher should I use in this case? expect(elm.isDisplayed()).toBe(true); expect(elm

Create custom jasmine matcher using Typescript

旧巷老猫 提交于 2019-12-01 15:47:17
I'm using jasmine on an angular2 project and having some trouble writing a custom matcher for a test. I want to be able to compare two relatively complex objects. I found this article which claims to solve the issue but it simply results in a typescript error stating that it doesn't recognize the new method on jasmine's Matchers object. The relevant code is this: declare module jasmine { interface Matchers { toBeNumeric(): void; } } Another article gives a similar, but slightly different solution that gives the same error. declare namespace jasmine { interface Matchers { toHaveText(expected:

Create custom jasmine matcher using Typescript

谁说胖子不能爱 提交于 2019-12-01 14:20:05
问题 I'm using jasmine on an angular2 project and having some trouble writing a custom matcher for a test. I want to be able to compare two relatively complex objects. I found this article which claims to solve the issue but it simply results in a typescript error stating that it doesn't recognize the new method on jasmine's Matchers object. The relevant code is this: declare module jasmine { interface Matchers { toBeNumeric(): void; } } Another article gives a similar, but slightly different

Is there a way to add a Jasmine matcher to the whole environment

北城余情 提交于 2019-11-30 04:14:43
There are plenty of documents that show how to add a matcher to a Jasmine spec ( here , for example). Has anyone found a way to add matchers to the whole environment; I'm wanting to create a set of useful matchers to be called by any and all tests, without copypasta all over my specs. Currently working to reverse engineer the source, but would prefer a tried and true method, if one exists. Sure, you just call beforeEach() without any spec scoping at all, and add matchers there. This would globally add a toBeOfType matcher. beforeEach(function() { var matchers = { toBeOfType: function

Checking two boundaries with Jasmine (between matcher)

百般思念 提交于 2019-11-29 08:17:41
问题 In Jasmine, there are toBeGreaterThan and toBeLessThan matchers. What if I want to check an integer value in a specific range? Is there anything like toBeInBetween matcher? Currently, I can solve it in two separate expect calls: var x = 3; expect(x).toBeGreaterThan(1); expect(x).toBeLessThan(10); 回答1: You can run the boolean comparison and assert the result is true : expect(x > 1 && x < 10).toBeTruthy(); Also, there is toBeWithinRange() custom matcher introduced by jasmine-matchers: expect(x)

Is there a way to add a Jasmine matcher to the whole environment

爷,独闯天下 提交于 2019-11-29 01:32:16
问题 There are plenty of documents that show how to add a matcher to a Jasmine spec (here, for example). Has anyone found a way to add matchers to the whole environment; I'm wanting to create a set of useful matchers to be called by any and all tests, without copypasta all over my specs. Currently working to reverse engineer the source, but would prefer a tried and true method, if one exists. 回答1: Sure, you just call beforeEach() without any spec scoping at all, and add matchers there. This would