Questions tagged [jasmine-matchers]
14 questions
256
votes
5 answers
toBe(true) vs toBeTruthy() vs toBeTrue()
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…

alecxe
- 462,703
- 120
- 1,088
- 1,195
37
votes
4 answers
Is there a way to add a Jasmine matcher to the whole environment
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,…

Dancrumb
- 26,597
- 10
- 74
- 130
16
votes
4 answers
Create custom jasmine matcher using Typescript
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…

d512
- 32,267
- 28
- 81
- 107
14
votes
1 answer
How to let TypeScript know about custom Jest matchers?
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:…

johncol
- 584
- 1
- 7
- 13
13
votes
1 answer
Checking two boundaries with Jasmine (between matcher)
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 =…

alecxe
- 462,703
- 120
- 1,088
- 1,195
6
votes
2 answers
Failed expectation: "Expected [ ] to be empty array."
Here is the failing test:
describe("Checking errors", function () {
var scope = {};
beforeEach(function () {
browser.get("/#endpoint");
browser.waitForAngular();
scope.page = new MyPage();
});
it("should…

alecxe
- 462,703
- 120
- 1,088
- 1,195
4
votes
1 answer
Use Jasmine custom matcher with Angular CLI project
I have a simple need: to use my own custom matchers in Jasmine unit tests within an Angular CLI project (Angular v6).
A couple constraints:
I do not want to modify anything under node_modules; this project has to be able to go through my build…

Michael Sorens
- 35,361
- 26
- 116
- 172
4
votes
3 answers
How to add custom matchers to jasmine globally?
I'd need a replacement for the jasmine.addMatchers function gone in version 1.3. The current API allows to add matchers to a describe block, but I'd prefer to be able to use my matchers everywhere without adding them again and again.
Is there a…

maaartinus
- 44,714
- 32
- 161
- 320
3
votes
1 answer
How to write a custom matcher for jasmine to find if the object properties lie within a range of object property values?
I am trying to implement a custom matcher for Jasmine where I would like to check if the given object property values lie within the range of the other two object property values.
Here is what I got so far:
let matcher = {
toLieWithin:…

zelda
- 753
- 2
- 8
- 19
3
votes
3 answers
jasmine text verification: How to normalize text?
I have a page with text in different HTML elements and I want a quick way of verifying the text.
Using jasmine and jasmine-query to load HTML and test DOM.
For example, I want to verify text in this HTML