Skip to content

build: avoid 404 warnings in Karma tests #15136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/lib/icon/icon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ describe('MatIcon', () => {
let fakePath: string;

beforeEach(async(() => {
fakePath = '/fake-path';
// The $ prefix tells Karma not to try to process the
// request so that we don't get warnings in our logs.
fakePath = '/$fake-path';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here that explains the $?


TestBed.configureTestingModule({
imports: [HttpClientTestingModule, MatIconModule],
Expand Down Expand Up @@ -630,7 +632,7 @@ describe('MatIcon', () => {

// We use a regex to match here, rather than the exact value, because different browsers
// return different quotes through `getAttribute`, while some even omit the quotes altogether.
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/fake-path#blur['"]?\)$/);
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/\$fake-path#blur['"]?\)$/);

tick();
}));
Expand All @@ -651,17 +653,18 @@ describe('MatIcon', () => {
fixture.detectChanges();
let circle = fixture.nativeElement.querySelector('mat-icon svg circle');

expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/fake-path#blur['"]?\)$/);
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/\$fake-path#blur['"]?\)$/);
tick();
fixture.destroy();

fakePath = '/another-fake-path';
fakePath = '/$another-fake-path';
fixture = TestBed.createComponent(IconFromSvgName);
fixture.componentInstance.iconName = 'fido';
fixture.detectChanges();
circle = fixture.nativeElement.querySelector('mat-icon svg circle');

expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/another-fake-path#blur['"]?\)$/);
expect(circle.getAttribute('filter'))
.toMatch(/^url\(['"]?\/\$another-fake-path#blur['"]?\)$/);
tick();
}));

Expand All @@ -683,13 +686,13 @@ describe('MatIcon', () => {

// We use a regex to match here, rather than the exact value, because different browsers
// return different quotes through `getAttribute`, while some even omit the quotes altogether.
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/fake-path#blur['"]?\)$/);
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/\$fake-path#blur['"]?\)$/);
tick();

fakePath = '/different-path';
fakePath = '/$different-path';
fixture.detectChanges();

expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/different-path#blur['"]?\)$/);
expect(circle.getAttribute('filter')).toMatch(/^url\(['"]?\/\$different-path#blur['"]?\)$/);
}));

});
Expand Down
13 changes: 13 additions & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@ module.exports = config => {
config.set({
basePath: path.join(__dirname, '..'),
frameworks: ['jasmine'],
middleware: ['fake-url'],
plugins: [
require('karma-jasmine'),
require('karma-browserstack-launcher'),
require('karma-sauce-launcher'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-sourcemap-loader'),
{'middleware:fake-url': ['factory', function() {
// Middleware that avoids triggering 404s during tests that need to reference
// image paths. Assumes that the image path will start with `/$`.
return function(request, response, next) {
if (request.url.indexOf('/$') === 0) {
response.writeHead(200);
return response.end();
}

next();
}
}]}
],
files: [
{pattern: 'node_modules/core-js/client/core.min.js', included: true, watched: false},
Expand Down