Skip to content

Commit

Permalink
add tests for notifyObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Rivet committed Oct 11, 2019
1 parent 1a7a470 commit 7c3edaa
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 11 deletions.
6 changes: 0 additions & 6 deletions dash-renderer/.babelrc

This file was deleted.

13 changes: 13 additions & 0 deletions dash-renderer/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
presets: [['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}], '@babel/preset-react'],
env: {
test: {
plugins: [
'@babel/plugin-transform-modules-commonjs'

This comment has been minimized.

Copy link
@Marc-Andre-Rivet

Marc-Andre-Rivet Oct 11, 2019

Contributor

to handle the not-previous-bundled code from @plotly/... packages

]
}
}
};
6 changes: 3 additions & 3 deletions dash-renderer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ module.exports = {
// transform: null,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/"
// ],
transformIgnorePatterns: [
"/node_modules/(?!@plotly).+\\.js"

This comment has been minimized.

Copy link
@Marc-Andre-Rivet

Marc-Andre-Rivet Oct 11, 2019

Contributor

by default all node_modules is ignored, we need the transform to work..

],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
8 changes: 7 additions & 1 deletion dash-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dash-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"@babel/preset-env": "^7.6.0",
"@babel/preset-react": "^7.0.0",
"@plotly/dash-component-plugins": "^1.0.1",
Expand Down Expand Up @@ -64,4 +65,4 @@
"webpack-serve": "^3.1.1",
"whatwg-fetch": "^2.0.2"
}
}
}
66 changes: 66 additions & 0 deletions dash-renderer/tests/notifyObservers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { notifyObservers } from "../src/actions";

const WAIT = 1000;

describe('notifyObservers', () => {
const thunk = notifyObservers({
id: 'id',
props: {},
undefined
});

it('executes if app is ready', async () => {
let done = false;
thunk(
() => { },
() => ({
graphs: {
InputGraph: {
hasNode: () => false,
dependenciesOf: () => [],
dependantsOf: () => [],
overallOrder: () => 0
}
},
isAppReady: true,
requestQueue: []
})
).then(() => { done = true; });

await new Promise(r => setTimeout(r, 0));
expect(done).toEqual(true);
});

it('waits on app to be ready', async () => {
let resolve;
const isAppReady = new Promise(r => {
resolve = r;
});

let done = false;
thunk(
() => { },
() => ({
graphs: {
InputGraph: {
hasNode: () => false,
dependenciesOf: () => [],
dependantsOf: () => [],
overallOrder: () => 0
}
},
isAppReady,
requestQueue: []
})
).then(() => { done = true; });

await new Promise(r => setTimeout(r, WAIT));

This comment has been minimized.

Copy link
@Marc-Andre-Rivet

Marc-Andre-Rivet Oct 11, 2019

Contributor

arbitrary amount of time to make sure it does not self-resolve after x amount of time

expect(done).toEqual(false);

resolve();

await new Promise(r => setTimeout(r, WAIT));
expect(done).toEqual(true);
});

});

0 comments on commit 7c3edaa

Please sign in to comment.