我有以下聚合物元素(对于纸质元素有多行导入并且firebase-auth已删除),我想使用Web Component Tester进行测试。
<dom-module id="my-login">
<template>
<firebase-auth id="auth" app-name="myapp" provider="email"></firebase-auth>
<paper-input id="email" label="Enter Email"></paper-input>
<paper-input id="password" label="Enter password" type="password"></paper-input>
<paper-button id="signin" on-tap="_signIn" raised primary>Login</paper-button>
<paper-button id="signup" on-tap="_register" secondary>Register</paper-button>
</template>
<script>
Polymer({
is: 'my-login',
ready: function () {
this.$.email.value = "xxxxxxxxxxxxxxx";
this.$.password.value = "zzzzzzzzzzz";
},
_signIn: function () {
const email = this.$.email.value;
const passw = this.$.password.value;
const sgn = this.$.auth;
sgn.signInWithEmailAndPassword(email, passw) // *** ERRROR HERE ***
.then(response => {
});
}
});
</script>
</dom-module>
使用以下测试套件(删除了大量不相关的详细信息):
<!doctype html>
<html lang="en">
<head>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../src/my-login.html">
</head>
<body>
<test-fixture id="login">
<template>
<my-login></my-login>
</template>
</test-fixture>
<script>
suite('LOGIN', function () {
var el, loginBtn;
setup(function () {
el = fixture("login");
loginBtn = el.$$('#signin');
});
test('user login', done => {
loginBtn.click();
flush(_ => {
done();
});
});
});
</script>
</body>
</html>
但是测试失败并出现以下错误:
Error: Cannot read property 'signInWithEmailAndPassword' of undefined
HTMLElement.signInWithEmailAndPassword at /bower_components/polymerfire/firebase-auth.html:211
HTMLElement._signIn at /src/my-login.html:20
我注意到错误说
Cannot read property signInWithEmailAndPassword of undefined
而不是
Cannot read property signInWithEmailAndPassword of null
代码段显示没有<link rel="import" ...>
,但在我的代码中,我确实包含了这些行,<paper-input>
和<paper-button>
的其他测试用例正在传递。
我做错了什么?
答案 0 :(得分:1)
我不确定以下是否是我自己问题的答案,但是
添加返回stub
的{{1}}后,错误消失,上述测试正在通过。但是,我仍然没有找出上面 undefined 错误的原因。
Promise