By postman testing is there anyway to call after test for cleanup - testing

In Junit test there is #After for the clenaup. Is there any similar way for the postman testing? If yes, how it should be done? Pls let me know.

I found the way to do it. I can simpley do it after the test as the last test for the clenaup
pm.test("Clean up after test", function () {
// Add your cleanup code here
});

Related

Mock or spyOn location.reload in angular unit testing

I have the function with location.reload(). How to write the angular unit test cases for test that reload functionality.
searchregion(){
location.reload();
}
I tried to written the test cases like below. But it shows error "Error: : could not find an object to spy upon reload()":
it('should test the reload functions', () =>{
spyOn(location, 'reload');
component.searchregion();
expect(location.reload).toHaveBeenCalled();
});
Can anyone please help me on this?

Detox - Possible to Force Fail Test?

Is there a way to force a test to fail in Detox? I haven't found anything in the documentation that says this can be the case. I am comparing two IDs that are hidden in an element and screen of my app and if they don't match, I want to fail the test.
if (element.id === screen.id) {
do
}
else {
*fail test*
}
it(`should invite User`, async () => {}
Or is it as easy as just throwing an error? Thanks
Detox itself delegates test logic to a test runner.
Detox delegates the actual JavaScript test-code execution to a dedicated test-runner. It supports the popular Jest and Mocha out of the box.
If you are using jest as the underlying test runner, you could just use its fail method as follows.
if (element.id === screen.id) {
do
}
else {
fail('test fails');
}
In mocha you could use the following function.
assert.fail("actual", "expected", "Error message");
We could also abuse the detox high level api to achieve the same (but less readable).
await waitFor(element(by.id(notVisible.id))).toBeVisible().withTimeout(5);

Make Mocha Wait for UI to Update

I'm using Mocha and Chai as part of the web-component-tester tool to write my tests. As part of those tests, I need to wait for a part of the UI to update before doing an assertion.
The only way I've been able to figure out how to do this successfully is by using a timeout:
test("should update image", function(done) {
setTimeout(function() {
assert.equal(document.querySelector(".tp-revslider-mainul .tp-revslider-slidesli:nth-child(1) .tp-bgimg").getAttribute("src"), "https://someurl/image.jpg");
done();
}, 5000);
});
Is there a better way? CasperJS has a waitFor function that is great in situations like these, but I'm not sure how to do the same in Mocha.
Thx.

Ember acceptance test - timeouts

I have a reasonably special use-case:
I have an input field which issues a search when the user has stopped typing for 500ms. This is developed as a reusable add-on.
I would like to write an acceptance test for this but I cannot make the tests pass properly. The first passes, the second doesn't.
Now, the Ember runloop has a nice description but it's behaviour is really "something else".
This is my helper to timeout the runloop:
import Ember from 'ember';
export default Ember.Test.registerAsyncHelper('pauseFor', function (time) {
return Ember.Test.promise(function (resolve) {
Ember.run.later(resolve, time);
});
});
And this is how I use it
it('should do something after 500ms', function () {
visit('/');
fillIn('.search-input', 'a');
pauseFor(500);
andThen(function () {
// do my assertions/expectations here...
});
});
This is the error I get:
The weird thing is that I have 2 test cases and the first passes happily.
I guess my question is:
How to do this properly? What am I missing here or what am I doing wrong? How can I just simply timeout the test case?
Thanks for the halp!

Qunit beforeEach, afterEach - async

Since start(), stop() will be removed in Qunit 2.0, what is the alternative for async setups and teardowns via the beforeEach, afterEach methods? For instance, if I want the beforeEach to wait for a promise to be finished?
QUnit basically wants people to stop using the global methods (not just start() and stop(), but also test(), expect(), etc). So, as of version 1.16.0, you should always use either the global namespace (QUnit) or the assert API argument passed into the test() functions. This includes the new async control:
QUnit.test( "testing async action", function( assert ) { // <-- note the `assert` argument here
var done = assert.async(); // tell QUnit we're doing async actions and
// hold onto the function it returns for later
setTimeout(function() { // do some async stuff
assert.ok( true, "This happened 100 ms later!" );
done(); // using the function returned from `assert.async()` we
// tell QUnit we're don with async actions
}, 100);
});
If you are familiar with the old start() and stop() way of doing things, you should see that this is extremely similar, but more compartmentalized and extensible.
Because the async() method call is on the assert argument into the test, it cannot be used in the beforeEach() function. If you have an example of how you were doing that before, please post it and we can try to figure out how to git it into the new way.
UPDATE
My mistake previously, the assert object is being passed into the beforeEach and afterEach callbacks on modules, so you should be able to do the same logic that you would do for a test:
QUnit.module('set of tests', {
beforeEach: function(assert) {
var done = assert.async();
doSomethingAsync(function() {
done(); // tell QUnit you're good to go.
});
}
});
(tested in QUnit 1.17.1)
Seeing that nobody has answered the beforeEach/afterEach part: a test suite is supposed to run as soon as the page loads. When that is not immediately possible, then resort to configuring QUnit:
QUnit.config.autostart = false;
and continue with setting up your test suite (initializing tests, feeding them to QUnit, asynchronously waiting for some components to load, be it AJAX or anything else), your site, and finally, when it's ready, just run:
QUnit.start();
QUnit's docsite has it covered.
Ember Qunit, has once exists beforeEach/setup, afterEach/teardown co-exist for a little while.
See PR: https://github.com/emberjs/ember-qunit/pull/125