mock-pipe
Version:
Function creating a mock based on a passed in pipe for test
73 lines (72 loc) • 3.31 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var testing_1 = require("@angular/core/testing");
var platform_browser_1 = require("@angular/platform-browser");
var testing_2 = require("@angular/platform-browser-dynamic/testing");
var mock_pipe_1 = require("./mock_pipe");
var ExamplePipe = (function () {
function ExamplePipe() {
this.transform = function (args) { return 'hi'; };
}
ExamplePipe = __decorate([
core_1.Pipe({ name: 'mockedPipe' })
], ExamplePipe);
return ExamplePipe;
}());
exports.ExamplePipe = ExamplePipe;
var AnotherExamplePipe = (function () {
function AnotherExamplePipe() {
this.transform = function (args) { return 'hi'; };
}
AnotherExamplePipe = __decorate([
core_1.Pipe({ name: 'anotherMockedPipe' })
], AnotherExamplePipe);
return AnotherExamplePipe;
}());
exports.AnotherExamplePipe = AnotherExamplePipe;
var ExampleComponent = (function () {
function ExampleComponent() {
this.someStuff = 'bah';
}
ExampleComponent = __decorate([
core_1.Component({
selector: 'example-component',
template: "\n <span id=\"examplePipe\">{{ someStuff | mockedPipe: 'foo' }}</span>\n <span id=\"anotherExamplePipe\">{{ someStuff | anotherMockedPipe: 'fighters' }}</span>\n "
})
], ExampleComponent);
return ExampleComponent;
}());
exports.ExampleComponent = ExampleComponent;
describe('MockPipe', function () {
var fixture;
testing_1.getTestBed().initTestEnvironment(testing_2.BrowserDynamicTestingModule, testing_2.platformBrowserDynamicTesting());
beforeEach(testing_1.async(function () {
testing_1.TestBed.configureTestingModule({
declarations: [
ExampleComponent,
mock_pipe_1.MockPipe(ExamplePipe, function () { return 'foo'; }),
mock_pipe_1.MockPipe(AnotherExamplePipe)
]
})
.compileComponents();
}));
beforeEach(function () {
fixture = testing_1.TestBed.createComponent(ExampleComponent);
fixture.detectChanges();
});
it('should not display the word hi that is output by the unmocked pipe, because it is now mocked', function () {
expect(fixture.debugElement.query(platform_browser_1.By.css('#anotherExamplePipe')).nativeElement.innerHTML).toEqual('');
});
describe('with transform override', function () {
it('should return the result of the provided transform function', function () {
expect(fixture.debugElement.query(platform_browser_1.By.css('#examplePipe')).nativeElement.innerHTML).toEqual('foo');
});
});
});