Start front end test example
This commit is contained in:
parent
7cd399db07
commit
9d03679063
@ -18,6 +18,7 @@
|
||||
"dependencies": {
|
||||
"axios": "^0.21.0",
|
||||
"chai": "^4.2.0",
|
||||
"esm": "^3.2.25",
|
||||
"flitter-auth": "^0.19.1",
|
||||
"flitter-cli": "^0.16.0",
|
||||
"flitter-di": "^0.5.0",
|
||||
@ -31,7 +32,7 @@
|
||||
"sinon": "^9.2.1"
|
||||
},
|
||||
"scripts": {
|
||||
"test_units": "./node_modules/.bin/mocha --reporter spec test"
|
||||
"test_frontend": "./node_modules/.bin/mocha -r esm --reporter spec test/frontend",
|
||||
"test_backend": "./node_modules/.bin/mocha --reporter spec test/backend"
|
||||
}
|
||||
|
||||
}
|
||||
|
0
test/backend/.gitkeep
Normal file
0
test/backend/.gitkeep
Normal file
0
test/frontend/.gitkeep
Normal file
0
test/frontend/.gitkeep
Normal file
43
test/frontend/module_routing.spec.js
Normal file
43
test/frontend/module_routing.spec.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import {router} from '../../frontend/src/module/routing'
|
||||
|
||||
// Since we're testing code meant for the browser, not node, mock this
|
||||
global.window = global
|
||||
|
||||
describe('the html5 history router', function() {
|
||||
it('should be a functional class', function() {
|
||||
expect(router).to.exist
|
||||
})
|
||||
|
||||
it('should use the global base path', function() {
|
||||
global.APP_BASE_PATH = 'testing-1-2-3'
|
||||
expect(router.base_path).to.be.equal('testing-1-2-3')
|
||||
})
|
||||
|
||||
it('should navigate using the History API', function() {
|
||||
const args = { test: 123 }
|
||||
|
||||
// mock this history API
|
||||
global.history = {
|
||||
pushState: sinon.spy()
|
||||
}
|
||||
|
||||
router.navigate('some-path', args)
|
||||
expect(global.history.pushState.calledOnce).to.be.true
|
||||
expect(global.history.pushState.getCall(0).args[1]).to.be.equal('some-path')
|
||||
expect(router.route_args).to.be.equal(args)
|
||||
})
|
||||
|
||||
it('should call subscribers on navigate', function() {
|
||||
const handler = sinon.spy()
|
||||
const args = { test: 123 }
|
||||
|
||||
router.subscribe(handler)
|
||||
router.navigate('some-other-path', args)
|
||||
|
||||
expect(handler.calledOnce).to.be.true
|
||||
expect(handler.getCall(0).args[0]).to.be.equal('some-other-path')
|
||||
expect(handler.getCall(0).args[1]).to.be.equal(args)
|
||||
})
|
||||
})
|
@ -1448,6 +1448,11 @@ escape-string-regexp@4.0.0:
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
|
||||
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==
|
||||
|
||||
esm@^3.2.25:
|
||||
version "3.2.25"
|
||||
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
|
||||
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==
|
||||
|
||||
esprima-fb@^10001.1.0-dev-harmony-fb:
|
||||
version "10001.1.0-dev-harmony-fb"
|
||||
resolved "https://registry.yarnpkg.com/esprima-fb/-/esprima-fb-10001.1.0-dev-harmony-fb.tgz#f7efb452d3c8006dde6b3c59678604f7114a882c"
|
||||
|
Loading…
Reference in New Issue
Block a user