jest testing: fix syntax error
This commit is contained in:
parent
1f4071fd62
commit
9e39ee021a
1 changed files with 12 additions and 9 deletions
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
categories:
|
categories:
|
||||||
- Programming Languages
|
- Programming Languages
|
||||||
tags: [javascript, testing]
|
tags: [javascript, testing, jest]
|
||||||
---
|
---
|
||||||
|
|
||||||
# Testing with Jest
|
# Testing with Jest
|
||||||
|
@ -158,17 +158,20 @@ Note: although we are importing `someFunction` we are not actually importing the
|
||||||
|
|
||||||
The same approaches (with minor differences) can be used with classes:
|
The same approaches (with minor differences) can be used with classes:
|
||||||
|
|
||||||
Using inline:
|
Using inline (where the class is not the default export):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
jest.mock("./SomeClass", () => {
|
jest.mock("./SomeClass", () => {
|
||||||
return jest.fn().mockImplementation(() => {
|
return {
|
||||||
return {
|
SomeClass: jest.fn().mockImplementation(() => {
|
||||||
someFunction: jest.fn(() => "value"),
|
return {
|
||||||
someFunctionWithParam: jest.fn((param) => ({ property: param })),
|
someFunction: jest.fn(() => "value"),
|
||||||
someAsyncFunction: jest.fn(() => Promise.resolve("value")),
|
someFunctionWithParam: jest.fn((param) => ({ property: param })),
|
||||||
};
|
someAsyncFunction: jest.fn(() => Promise.resolve("value")),
|
||||||
});
|
someOtherFunctionThatResolves: jest.fn().mockResolvedValue("some data"),
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue