smartrouter/test/test.browser.ts

33 lines
1021 B
TypeScript
Raw Normal View History

2020-07-15 18:51:17 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartrouter from '../ts/index';
let testrouter: smartrouter.SmartRouter;
tap.test('first test', async () => {
testrouter = new smartrouter.SmartRouter({});
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
});
tap.test('should handle a route change', async (tools) => {
const done = tools.defer();
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
expect(routeInfoArg.params.any).to.equal('hello');
done.resolve();
});
testrouter.pushUrl('/myawesomeroute/hello');
await done.promise;
});
tap.test('should handle a route change', async (tools) => {
const done = tools.defer();
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
expect(routeInfoArg.params.wow).to.equal('hello2');
done.resolve();
});
testrouter.pushUrl('/myawesomeroute2/hello2');
await done.promise;
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2');
});
tap.start();