mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 17:15:48 +00:00
routesRegexp spec uses jest methods
This commit is contained in:
parent
6d75b306fb
commit
eeb72f2760
2 changed files with 32 additions and 40 deletions
32
tests/routesRegexp.spec.js
Normal file
32
tests/routesRegexp.spec.js
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue