Skip to content

Commit

Permalink
Tests: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 2, 2020
1 parent 7475650 commit 77781f7
Show file tree
Hide file tree
Showing 6 changed files with 428 additions and 29 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"simple-invariant": "^2.0.0"
},
"devDependencies": {
"@overlook/plugin-fs": "^0.1.1",
"@overlook/plugin-match": "^0.8.3",
"@overlookmotel/eslint-config": "^7.2.1",
"@overlookmotel/eslint-config-jest": "^4.1.1",
"@overlookmotel/eslint-config-node": "^2.1.2",
Expand Down
76 changes: 76 additions & 0 deletions test/handle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* --------------------
* @overlook/plugin-react module
* Handle tests
* ------------------*/

'use strict';

// Modules
const Route = require('@overlook/route'),
matchPlugin = require('@overlook/plugin-match'),
{HANDLE_ROUTE} = matchPlugin,
reactPlugin = require('@overlook/plugin-react'),
{REACT_ROOT, REACT_ROUTER, ROUTER_ADD_ROUTE} = reactPlugin;

// Init
const {spy} = require('./support/index.js');

// Tests

const ReactRoute = Route.extend(reactPlugin),
MatchRoute = Route.extend(matchPlugin),
ReactMatchRoute = MatchRoute.extend(reactPlugin);

describe('Handle', () => {
describe('`.handle()` on normal route', () => {
it('for root, returns undefined', async () => {
const root = new ReactRoute();
root[REACT_ROOT] = root;
await root.init();
expect(root.handle()).toBeUndefined();
});

it('for child, calls `.handle()` on root', async () => {
const root = new ReactRoute();
root[REACT_ROOT] = root;
root[REACT_ROUTER] = root;
root[ROUTER_ADD_ROUTE] = () => {};
const res = {};
root.handle = spy(() => res);
const child = new ReactRoute({name: 'child'});
root.attachChild(child);
await root.init();

const req = {};
expect(child.handle(req)).toBe(res);
expect(root.handle).toHaveBeenCalledTimes(1);
expect(root.handle).toHaveBeenCalledWith(req);
});
});

describe('[HANDLE_ROUTE]()` on match route', () => {
it('for root, returns undefined', async () => {
const root = new ReactMatchRoute();
root[REACT_ROOT] = root;
await root.init();
expect(root[HANDLE_ROUTE]()).toBeUndefined();
});

it('for child, calls `[HANDLE_ROUTE]()` on root', async () => {
const root = new ReactMatchRoute();
root[REACT_ROOT] = root;
root[REACT_ROUTER] = root;
root[ROUTER_ADD_ROUTE] = () => {};
const res = {};
root[HANDLE_ROUTE] = spy(() => res);
const child = new ReactMatchRoute({name: 'child'});
root.attachChild(child);
await root.init();

const req = {};
expect(child[HANDLE_ROUTE](req)).toBe(res);
expect(root[HANDLE_ROUTE]).toHaveBeenCalledTimes(1);
expect(root[HANDLE_ROUTE]).toHaveBeenCalledWith(req);
});
});
});
29 changes: 0 additions & 29 deletions test/index.test.js

This file was deleted.

0 comments on commit 77781f7

Please sign in to comment.