我在一个项目中使用@angular@9.0.7,@ngneat/spectator@5.3.1
(与Jest),当我运行时Inputmask@5.0.3
一切都在应用程序上运行,但是当我尝试运行一个测试套件时它失败了:ng serve
ng build
@Pipe
Inputmask
@Pipe
:
import { Pipe, PipeTransform } from '@angular/core';
import Inputmask from 'inputmask';
@Pipe({
name: 'appSomePipe',
})
export class SomePipe implements PipeTransform {
transform(value: string): string {
return Inputmask.format(value, {
jitMasking: true,
mask: '1111-1',
});
}
}
@Spec
:
import { createPipeFactory, SpectatorPipe } from '@ngneat/spectator/jest';
import { SomePipe } from './some.pipe';
describe('SomePipe', () => {
let spectator: SpectatorPipe<SomePipe>;
const createPipe = createPipeFactory(SomePipe);
it('test', () => {
spectator = createPipe(`{{ '11111' | appSome }}`);
expect(spectator.element).toHaveText('1111-1');
});
});
当我运行时ng test
,它显示:
ReferenceError: customElements 未定义
2 |
> 3 | import Inputmask from 'inputmask';
PS:这个错误只出现在 Angular 9 中,在 Angular 8 中所有测试都成功通过了。