routesRegexp spec uses jest methods

This commit is contained in:
NikolaBorislavovHristov 2019-12-09 13:15:47 +02:00
parent 6d75b306fb
commit eeb72f2760
2 changed files with 32 additions and 40 deletions

View file

@ -0,0 +1,32 @@
const routesRegexp = require('../src/common/routesRegexp');
describe('routesRegexp', () => {
describe('intro route regexp', () => {
it('match /intro', async () => {
expect(Array.from('/intro'.match(routesRegexp.intro.regexp)))
.toEqual(['/intro']);
});
it('match /intro/', async () => {
expect(Array.from('/intro/'.match(routesRegexp.intro.regexp)))
.toEqual(['/intro/']);
});
it('not match /intro/$', async () => {
expect('/intro/$'.match(routesRegexp.intro.regexp))
.toBe(null);
});
});
describe('board route regexp', () => {
it('match /', async () => {
expect(Array.from('/'.match(routesRegexp.board.regexp)))
.toEqual(['/']);
});
it('not match /$', async () => {
expect('/$'.match(routesRegexp.board.regexp))
.toBe(null);
});
});
});

View file

@ -1,40 +0,0 @@
const routesRegexp = require('../src/common/routesRegexp');
const urlParamsMatch = (result, urlParams) => {
expect(Array.isArray(result)).toBe(true);
expect(result.length).toBe(urlParams.length);
urlParams.forEach((urlParam, index) => {
expect(result[index]).toBe(urlParam);
});
};
describe('routes regex', () => {
describe('intro regexp', () => {
it('goes to /intro', async () => {
const result = '/intro'.match(routesRegexp.intro.regexp);
urlParamsMatch(result, ['/intro']);
});
it('goes to /intro/', async () => {
const result = '/intro/'.match(routesRegexp.intro.regexp);
urlParamsMatch(result, ['/intro/']);
});
it('goes to /intro/<random_input>', async () => {
const result = '/intro/a'.match(routesRegexp.intro.regexp);
expect(result).toBe(null);
});
});
describe('board regexp', () => {
it('goes to /', async () => {
const result = '/'.match(routesRegexp.board.regexp);
urlParamsMatch(result, ['/']);
});
it('goes to /<random_input>', async () => {
const result = '/a'.match(routesRegexp.board.regexp);
expect(result).toBe(null);
});
});
});