Angular 2 / Ionic 2 TypeError: zxcvbn_1.default 不是一个函数



用Jasmine和Karma进行测试,我正在使用zxcvbn库进行一些密码强度计算。当我尝试通过调用下面的updateScore()函数对其运行规范时,这将失败。

private updateScore(): void {
    const analysis = zxcvbn(this.password)
    this.score = analysis.score;
    this.comment = analysis.feedback.warning || analysis.feedback.suggestions[0];
  }

在导入中,我正在做import zxcvbn from 'zxcvbn';

这在应用程序中有效,即使在我构建和模拟时也是如此,但在规范中,它给了我这个错误:

FAILED TESTS:
  PasswordStrengthChecker
    ✖ should update the score when password changes
      Chrome 55.0.2883 (Mac OS X 10.11.6)
    TypeError: zxcvbn_1.default is not a function
        at PasswordStrengthChecker.updateScore (webpack:///src/components/password-strength-checker/password-strength-checker.ts:25:28 <- src/test.ts:93920:40)
        at PasswordStrengthChecker.ngOnChanges (webpack:///src/components/password-strength-checker/password-strength-checker.ts:20:9 <- src/test.ts:93916:14)
        at Object.<anonymous> (webpack:///src/components/password-strength-checker/password-strength-checker.spec.ts:27:13 <- src/test.ts:185997:18)
        at ZoneDelegate.invoke (webpack:///~/zone.js/dist/zone.js:232:0 <- src/test.ts:183822:26)
        at ProxyZoneSpec.onInvoke (webpack:///~/zone.js/dist/proxy.js:79:0 <- src/test.ts:130574:39)
        at ZoneDelegate.invoke (webpack:///~/zone.js/dist/zone.js:231:0 <- src/test.ts:183821:32)
        at Zone.run (webpack:///~/zone.js/dist/zone.js:114:0 <- src/test.ts:183704:43)
        at Object.<anonymous> (webpack:///~/zone.js/dist/jasmine-patch.js:102:0 <- src/test.ts:130289:34)

我在使用时遇到了这个问题

import linkifyStr from 'linkifyjs/string';

而不是

import * as linkifyStr from 'linkifyjs/string';

相关内容

  • 没有找到相关文章

最新更新