Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test should fail instead of throwing FunctionCallMatchError #450

Open
wip0 opened this issue Feb 5, 2018 · 1 comment
Open

Test should fail instead of throwing FunctionCallMatchError #450

wip0 opened this issue Feb 5, 2018 · 1 comment

Comments

@wip0
Copy link

wip0 commented Feb 5, 2018

Here is my test code

@AsyncTest('Async)
public test() {
    const cb = createFunctionSpy();
    setTimeout(() => {
        Expect(cb).toHaveBeenCalled().exactly(1);
        Expect(cb).toHaveBeenCalledWith(ch1, msg1);
}, 0);
}

I don't know which line trhow error but it should fail the test case instead of throwing any error.

...\node_modules\alsatian\core\matchers\function-matcher.js:179
            throw new errors_1.FunctionCallMatchError(this.actualValue, this.shouldMatch);
            ^
FunctionCallMatchError: Expected function to be called.
@wip0
Copy link
Author

wip0 commented Feb 5, 2018

Actually, it is my fault to write the above bad code. So, I changed my code to this.

    @Timeout(10000)
    @AsyncTest('Async')
    public test(): Promise<void> {
        return new Promise(async (resolve, reject) => {
            const cb = createFunctionSpy();
            await new Promise((_) => setTimeout(() => _(), 2));
            Expect(cb).toHaveBeenCalled().exactly(0);
        });
    }

The test case failed but there is an UnhandledPromiseRejectionWarning and wait until timeout reach.

But finally I have found the solution.

    @FocusTest
    @Timeout(10000)
    @AsyncTest('Async')
    public test(): Promise<void> {
        return new Promise((resolve, reject) => {
            const cb = createFunctionSpy();
            new Promise((_) => setTimeout(() => _(), 2)).then(() => {
                Expect(cb).toHaveBeenCalled().exactly(0);
                resolve();
            }).catch((error) => reject(error));
        });
    }

With this way, it failed immediately and not wait anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant