lundi 21 août 2017

Asynchronus assertion in javascript testing

I'm trying to test a react project, and I have the following asynchronous test that should fail here: fail("Fail: " + response.status)

What do I need to do to make this happen?

describe('Test dummy data endpoint', () => {
        it('Test postman-echo for 2 element todo list', (done) => {
                var options = {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(["One", "Two"])
                }
                var promise = fetch('http://ift.tt/2wrLxFB', options);
                promise.then(
                    function (response) {
                        it('Status should be 200', (stschk) => {
                            fail("Fail: " + response.status)
                            stschk()
                        })
                        return response.json()
                    },
                    function (error) {
                        fail("Failed", error)
                    }
                )
                done()
            }
        )
    }
)

Aucun commentaire:

Enregistrer un commentaire