From eeb72f27603b028ba7c36d564ae7d477b432203f Mon Sep 17 00:00:00 2001 From: NikolaBorislavovHristov Date: Mon, 9 Dec 2019 13:15:47 +0200 Subject: [PATCH] routesRegexp spec uses jest methods --- tests/routesRegexp.spec.js | 32 ++++++++++++++++++++++++++ tests/routesRegexpTests.spec.js | 40 --------------------------------- 2 files changed, 32 insertions(+), 40 deletions(-) create mode 100644 tests/routesRegexp.spec.js delete mode 100644 tests/routesRegexpTests.spec.js diff --git a/tests/routesRegexp.spec.js b/tests/routesRegexp.spec.js new file mode 100644 index 000000000..ebf236a30 --- /dev/null +++ b/tests/routesRegexp.spec.js @@ -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); + }); + }); +}); diff --git a/tests/routesRegexpTests.spec.js b/tests/routesRegexpTests.spec.js deleted file mode 100644 index e9bb84050..000000000 --- a/tests/routesRegexpTests.spec.js +++ /dev/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/', 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 /', async () => { - const result = '/a'.match(routesRegexp.board.regexp); - expect(result).toBe(null); - }); - }); -});