Closed ANierbeck closed 10 months ago
Can you share the repo where you are having issues with this? The proposed fix is not correct IMO. We should investigate why it's not working for you.
Needed here: https://github.com/ANierbeck/ioBroker.stromgedacht
I'll take a look. For explanation, what you're doing here
it("Check Zip Code ist set", (done) => {
const promise = new Promise(async (resolve) => {
// Perform the test
await harness.startAdapterAndWait();
await harness.databases.adapter.config.zipcode.should.equal(zipCode);
resolve();
});
done();
return promise;
});
is starting the adapter and performing some check in the background, but before this ever happens, you end the test with a success by calling done()
. So your test effectively does nothing at all.
Ok we should update the readme to use async
functions instead of returning Promises. If I change your test to
it("Check Zip Code ist set", async () => {
await harness.startAdapterAndWait();
await harness.databases.adapter.config.zipcode.should.equal(zipCode);
});
I get the following error:
1) Adapter integration tests
User-defined tests
Test retrieveJson()
Check Zip Code ist set:
TypeError: Cannot read properties of undefined (reading 'adapter')
at Context.<anonymous> (test/integration.js:65:29)
which is the root of your issue - harness
has no property databases
.
Ok, in that case the sample is missing the crucial information about how to get the database connected to the adapter. Unfortunately I wasn't able to find any working sample.
With some more analyzing, figured out, the before method doesn't have the database yet. This one goes on me. Never the less it still seems like the setting of a config only works for the second invocation, coming to the next problem. Multiple it-Tests in a suit don't work, only the first.
So let's close this issue then.
When trying to build integration tests according to the example shown in the #README.MD, the tests always failed. Turned out the test method is missing a "done" method. I'm not sure if this is something a new version of the testframework requires or something else.
` it("Should work", () => { return new Promise(async (resolve) => { // Start the adapter and wait until it has started await harness.startAdapterAndWait();
needs to be like the following:
` it("Should work", (done) => { const promise = Promise(async (resolve) => { // Start the adapter and wait until it has started await harness.startAdapterAndWait();
`