Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace toBe with toEqual #1210

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions common-content/en/module/js1/anonymous-functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ In our Jest test, we wrote a function differently:

```js
function() {
expect(getOrdinalNumber(1)).toBe("1st");
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(21)).toEqual("21st");
}
```

Expand Down
6 changes: 3 additions & 3 deletions common-content/en/module/js1/arrow-functions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ Applying all of these techniques, we can rewrite our Jest test with fewer words:

```js
test("works for any number ending in 1", () => {
expect(getOrdinalNumber(1)).toBe("1st");
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(21)).toEqual("21st");
});
```

Expand Down
6 changes: 3 additions & 3 deletions common-content/en/module/js1/generalise/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ function getOrdinalNumber() {
}

test("works for any number ending in 1", function() {
expect(getOrdinalNumber(1)).toBe("1st");
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(21)).toEqual("21st");
});
```

Expand Down
14 changes: 7 additions & 7 deletions common-content/en/module/js1/outliers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function getOrdinalNumber(num) {
}

test("works for any number ending in 1", function () {
expect(getOrdinalNumber(1)).toBe("1st");
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(21)).toEqual("21st");
});
```

Expand All @@ -68,13 +68,13 @@ function getOrdinalNumber(num) {
}

test("works for any number ending in 1", function () {
expect(getOrdinalNumber(1)).toBe("1st");
expect(getOrdinalNumber(11)).toBe("11th");
expect(getOrdinalNumber(21)).toBe("21st");
expect(getOrdinalNumber(1)).toEqual("1st");
expect(getOrdinalNumber(11)).toEqual("11th");
expect(getOrdinalNumber(21)).toEqual("21st");
});

test("converts 2 to an ordinal number", function () {
expect(getOrdinalNumber(2)).toBe("2nd");
expect(getOrdinalNumber(2)).toEqual("2nd");
});
```

Expand Down
2 changes: 1 addition & 1 deletion common-content/en/module/js2/mean/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test("calculates the mean of a list of numbers", () => {
const currentOutput = calculateMean(list);
const targetOutput = 20;

expect(currentOutput).toBe(targetOutput); // 20 is (3 + 50 + 7) / 3
expect(currentOutput).toEqual(targetOutput); // 20 is (3 + 50 + 7) / 3
});
```

Expand Down
2 changes: 1 addition & 1 deletion common-content/en/module/js2/median/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test("calculates the median of a list of odd length", () => {
const currentOutput = calculateMedian(list);
const targetOutput = 30;

expect(currentOutput).toBe(targetOutput);
expect(currentOutput).toEqual(targetOutput);
});
```

Expand Down
6 changes: 3 additions & 3 deletions org-cyf-guides/content/testing/intro/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ For example, we could write a test to check that `countWords` behaves in a parti

```js
test("one word string gives a count of 1", function () {
expect(countWords("hello")).toBe(1);
expect(countWords("hello")).toEqual(1);
});
```

Expand All @@ -95,7 +95,7 @@ We use a function in Jest called `test` to write a test description - `"will cou
#### 2. Assertion

```js
expect(countWords("hello")).toBe(1);
expect(countWords("hello")).toEqual(1);
```

The assertion is the part of the test code that actually checks to see if something is true or not. In this example, we are claiming that the following is true:
Expand All @@ -104,7 +104,7 @@ The assertion is the part of the test code that actually checks to see if someth

Notice that the statement above is very similar to the syntax used in the test code.

The function [`toBe`](https://jestjs.io/docs/expect#tobevalue) ( which is part of the Jest framework ) is used to check that the return value of `countWords("hello")` and `1` are equal to each other. There are [many other functions](https://jestjs.io/docs/using-matchers) like `toEqual` which we can use to make different assertions.
The function [`toEqual`](https://jestjs.io/docs/expect#toequalvalue) ( which is part of the Jest framework ) is used to check that the return value of `countWords("hello")` and `1` are equal to each other. There are [many other functions](https://jestjs.io/docs/using-matchers) like `toHaveLength`, `toBeCloseTo`, and `toBe` which we can use to make different assertions.

### Pass ✅ or Fail ❌

Expand Down
Loading