Skip to content

Commit

Permalink
test: use jasmine.arrayContaining
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Jan 4, 2020
1 parent d4b1af0 commit 42a4df3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions modules/builders/src/prerender/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ describe('Prerender Builder Utils', () => {
const ROUTES_FILE = './routes.txt';
const ROUTES_FILE_CONTENT = ['/route1', '/route1', '/route2', '/route3'].join('\n');
const ROUTES = ['/route3', '/route3', '/route4'];
const GUESSED_ROUTES = [{ path: '/route4' }, { path: '/route5' }, { path: '/**' }, { path: '/user/:id' }];
const GUESSED_ROUTES: any = [
{ path: '/route4' },
{ path: '/route5' },
{ path: '/**' },
{ path: '/user/:id' },
];

const CONTEXT = {
workspaceRoot: '/path/to/angular/json',
Expand All @@ -46,34 +51,44 @@ describe('Prerender Builder Utils', () => {
guessRoutes: true,
} as PrerenderBuilderOptions;
const routes = await getRoutes(options, CONTEXT);
expect(routes).toContain('/route1');
expect(routes).toContain('/route2');
expect(routes).toContain('/route3');
expect(routes).toContain('/route4');
expect(routes).toContain('/route5');
expect(routes).toEqual(
jasmine.arrayContaining([
'/route1',
'/route2',
'/route3',
'/route4',
'/route5',
])
);
});

it('Should return only the given routes', async () => {
const options = { routes: ROUTES } as PrerenderBuilderOptions;
const routes = await getRoutes(options, CONTEXT);
expect(routes).toContain('/route3');
expect(routes).toContain('/route4');
expect(routes).toEqual(jasmine.arrayContaining([
'/route3',
'/route4',
]));
});

it('Should return the routes from the routesFile', async () => {
const options = { routesFile: ROUTES_FILE } as PrerenderBuilderOptions;
const routes = await getRoutes(options, CONTEXT);
expect(routes).toContain('/route1');
expect(routes).toContain('/route2');
expect(routes).toContain('/route3');
expect(routes).toEqual(jasmine.arrayContaining([
'/route1',
'/route2',
'/route3',
]));
});

it('Should catch errors thrown by parseAngularRoutes', async () => {
const options = { routes: ROUTES, guessRoutes: true } as PrerenderBuilderOptions;
parseAngularRoutesSpy.and.throwError('Test Error');
const routes = await getRoutes(options, CONTEXT);
expect(routes).toContain('/route3');
expect(routes).toContain('/route4');
expect(routes).toEqual(jasmine.arrayContaining([
'/route3',
'/route4',
]));
expect(loggerErrorSpy).toHaveBeenCalled();
});
});
Expand Down

0 comments on commit 42a4df3

Please sign in to comment.