如何编写AWS Cognito服务的单元测试用例[关闭]

问题描述 投票:-1回答:1
我是单元测试用例的新手。我被困在编写如下所述的AWS Cognito服务的单元测试用例中。

下面是代码。

signUp(userData) { return new Promise((resolved, reject) => { const userPoolData = new AWSCognito.CognitoUserPool(this._POOL_DATA); let userAttribute = []; userAttribute.push( new AWSCognito.CognitoUserAttribute({ Name: "email", Value: userData.email }), new AWSCognito.CognitoUserAttribute({ Name: "custom:role", Value: userData.role }), ); userPoolData.signUp(userData.email, userData.password, userAttribute, null, function (err, result) { if (err) { reject(err); } else { resolved(result); } }); }); }

angular karma-jasmine ionic4
1个回答
0
投票
import * as AWS from 'the-dependency'; // dependency where AWSCognito comes from it('should sign up user', async done => { // CognitoUserPool return this spyOn(AWS.AWSCognito, 'CognitoUserPool').and.returnValue({ signUp: (email, password, userAttribute, fn) => fn(null, true); // may have to check the mock });; const result = await component.signUp({ email: '...', password: '...', role: '...' }); // wait until pending promises are done await fixture.whenStable(); expect(result).toBe(true); // resolved it to true in `signUp` mock });
签出:Jasmine - How to write test case for AWS service authenticateUser?
© www.soinside.com 2019 - 2024. All rights reserved.