Skip to content

Commit 97fc902

Browse files
committed
fix(recipes): fix "testing derived state" not working correctly in code sandbox
import selectors extension in spec file instead of through test setup since code sandbox does not support custom jest config files
1 parent 61418c3 commit 97fc902

4 files changed

Lines changed: 2 additions & 12 deletions

File tree

recipes/basics/testing-derived-state/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@ Before we start let's install all the packages we need.
1212
npm i @simplux/core @simplux/selectors redux -S
1313
```
1414

15-
We also need to activate the selectors extension by importing the package. You can either add this import to every test file or do it once globally with the mechanism your test framework provides. This recipe uses [Jest](https://jestjs.io/) which allows us to specify a global setup file.
15+
We also need to activate the selectors extension by importing the package. You can either add this import to every test file or do it once globally with the mechanism your test framework provides (e.g. [Jest](https://jestjs.io/) allows you to configure `setupFiles` where you can place this import).
1616

1717
```ts
18-
// in jest.setup.ts
1918
import '@simplux/selectors'
2019
```
2120

22-
```js
23-
// in jest.config.js
24-
module.exports = {
25-
setupFiles: ['<rootDir>/jest.setup.ts'],
26-
// + any other config you need
27-
}
28-
```
29-
3021
Now we're ready to go.
3122

3223
Computing derived state for **simplux** modules is done with _selectors_. Selectors are very simple to test as you will see. For this recipe we use a simple counter module with two selectors.

recipes/basics/testing-derived-state/jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ module.exports = {
66
},
77
testMatch: ['<rootDir>/src/**/*.spec.ts'],
88
testPathIgnorePatterns: ['node_modules'],
9-
setupFiles: ['<rootDir>/jest.setup.ts'],
109
}

recipes/basics/testing-derived-state/jest.setup.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

recipes/basics/testing-derived-state/src/counter.module.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// this code is part of the simplux recipe "testing state changes":
22
// https://github.com/MrWolfZ/simplux/tree/master/recipes/basics/testing-state-changes
33

4+
import '@simplux/selectors'
45
import { plus, plusOne, setCounterState } from './counter.module'
56

67
describe('counter module', () => {

0 commit comments

Comments
 (0)