Pact-js: Test with Jest AND Angular not end correctly

Created on 20 Sep 2018  ·  3Comments  ·  Source: pact-foundation/pact-js

Software versions

  • OS: Windows 10
  • Consumer Pact library: PactJs 5.9.1
  • Node Version: 9.11.1

Expected behaviour

The test finish correctly

Actual behaviour

The test passed and the json file is generated but it end with an error that is not related to the actual test.
Error :

FAIL  src/app/dummy-client.pact.ts
  Dummy API
    × should answer 200 (86ms)

  ● Dummy API › should answer 200

    Failed: "Registered interactions
    "

      at Env.fail (node_modules/jest-jasmine2/build/jasmine/Env.js:540:34)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        7.049s

All the interactions are correctly regitred as shown in the log beneath.

I had to adapt the documentation from there : https://github.com/pact-foundation/pact-js/tree/master/examples/jest

And I already adapate my pact test wrapper with : https://github.com/pact-foundation/pact-js/issues/67

Steps to reproduce

I made a repository : https://github.com/McKratt/jest-angular-example.

just run npm run pact to see the error happen

Relevant log files

I, [2018-09-20T09:50:26.882314 #5616] INFO -- : Registered expected interaction GET /dummies
D, [2018-09-20T09:50:26.883313 #5616] DEBUG -- : {
"description": "get dummies",
"request": {
"method": "GET",
"path": "/dummies"
},
"response": {
"status": 200,
"headers": {
},
"body": {
"value": "hello"
}
}
}
I, [2018-09-20T09:50:26.959310 #5616] INFO -- : Received request GET /dummies
D, [2018-09-20T09:50:26.959310 #5616] DEBUG -- : {
"path": "/dummies",
"query": "",
"method": "get",
"headers": {
"Accept": "application/json, text/plain, /",
"Referer": "http://localhost/",
"User-Agent": "Mozilla/5.0 (win32) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.12.0",
"Accept-Language": "en",
"Origin": "http://localhost",
"Host": "localhost:1234",
"Accept-Encoding": "gzip, deflate",
"Connection": "close",
"Version": "HTTP/1.1"
}
}
I, [2018-09-20T09:50:26.959310 #5616] INFO -- : Found matching response for GET /dummies
D, [2018-09-20T09:50:26.959310 #5616] DEBUG -- : {
"status": 200,
"headers": {
},
"body": {
"value": "hello"
}
}
I, [2018-09-20T09:50:26.992312 #5616] INFO -- : Verifying - interactions matched
I, [2018-09-20T09:50:27.002312 #5616] INFO -- : Cleared interactions
I, [2018-09-20T09:50:27.014312 #5616] INFO -- : Updating pact for MyProvider at C:/ieu/development/jest-angular-example/target/pacts/plandialog-frontend-myprovider.json
I, [2018-09-20T09:50:27.016310 #5616] INFO -- : ************************
I, [2018-09-20T09:50:27.017311 #5616] INFO -- : Updating existing file .C:/ieu/development/jest-angular-example/target/pacts/plandialog-frontend-myprovider.json as pactfile_write_mode is :update
I, [2018-09-20T09:50:27.017311 #5616] INFO -- : Only interactions defined in this test run will be updated.
I, [2018-09-20T09:50:27.017311 #5616] INFO -- : As interactions are identified by description and provider state, pleased note that if either of these have changed, the old interactions won't be removed from the pact file until the specs are next run with :pactfile_write_mode => :overwrite.
I, [2018-09-20T09:50:27.017311 #5616] INFO -- :
************************

Thank you in advance for any help

All 3 comments

Hi @McKratt,

It's a simple one. Jasmine's done will fail if anything is passed to it. provider.addInteraction() returns a string "Registered interactions", which fails the setup.

So you need to change this:

    }).then(done(), error => done.fail(error));

to something like:

    }).then(() => {done()}, error => done.fail(error));

Ok now I'm crying and I thnik is my last day as frontend developper.

@mefellows Thank you so much.

I tried to come up with something witty, but really - I just feel for you mate!

Was this page helpful?
0 / 5 - 0 ratings