Merge remote-tracking branch 'origin/t3chguy/jest' into travis/sourcemaps

This commit is contained in:
Travis Ralston 2020-01-09 16:00:13 -07:00
commit a8c8406ac4
41 changed files with 2002 additions and 1842 deletions

View file

@ -14,14 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import expect from 'expect';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sinon from 'sinon';
import MatrixReactTestUtils from 'matrix-react-test-utils';
import sdk from 'matrix-react-sdk';
import sdk from '../../../skinned-sdk';
import {MatrixClientPeg} from '../../../../src/MatrixClientPeg';
import * as test_utils from '../../../test-utils';
@ -33,11 +31,9 @@ const InteractiveAuthDialog = sdk.getComponent(
describe('InteractiveAuthDialog', function() {
let parentDiv;
let sandbox;
beforeEach(function() {
test_utils.beforeEach(this);
sandbox = test_utils.stubClient(sandbox);
test_utils.stubClient();
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
});
@ -45,12 +41,11 @@ describe('InteractiveAuthDialog', function() {
afterEach(function() {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
sandbox.restore();
});
it('Should successfully complete a password flow', function() {
const onFinished = sinon.spy();
const doRequest = sinon.stub().returns(Promise.resolve({a: 1}));
const onFinished = jest.fn();
const doRequest = jest.fn().mockResolvedValue({a: 1});
// tell the stub matrixclient to return a real userid
const client = MatrixClientPeg.get();
@ -96,8 +91,8 @@ describe('InteractiveAuthDialog', function() {
expect(submitNode.disabled).toBe(false);
ReactTestUtils.Simulate.submit(formNode, {});
expect(doRequest.callCount).toEqual(1);
expect(doRequest.calledWithMatch({
expect(doRequest).toHaveBeenCalledTimes(1);
expect(doRequest).toBeCalledWith(expect.objectContaining({
session: "sess",
type: "m.login.password",
password: "s3kr3t",
@ -105,12 +100,12 @@ describe('InteractiveAuthDialog', function() {
type: "m.id.user",
user: "@user:id",
},
})).toBe(true);
}));
// let the request complete
return sleep(1);
}).then(() => {
expect(onFinished.callCount).toEqual(1);
expect(onFinished.calledWithExactly(true, {a: 1})).toBe(true);
}).then(sleep(1)).then(() => {
expect(onFinished).toBeCalledTimes(1);
expect(onFinished).toBeCalledWith(true, {a: 1});
});
});
});