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

"eventually not a property of Assertion" error #30

Closed
johnlister opened this issue Mar 14, 2017 · 23 comments
Closed

"eventually not a property of Assertion" error #30

johnlister opened this issue Mar 14, 2017 · 23 comments

Comments

@johnlister
Copy link

While trying to run the tests (using the 2-reports branch). I get the following error:

[14:27:57] E/launcher - Error: TSError: ⨯ Unable to compile TypeScript
features\step_definitions\todo_user.steps.ts (31,14): Property 'eventually' does not exist on type 'Assertion'. (2339)
at getOutput (C:\src\js\tutorial-from-scripts-to-serenity\node_modules\ts-node\src\index.ts:312:17)
at C:\src\js\tutorial-from-scripts-to-serenity\node_modules\ts-node\src\index.ts:343:18
at Object.compile (C:\src\js\tutorial-from-scripts-to-serenity\node_modules\ts-node\src\index.ts:476:19)
at Module.m._compile (C:\src\js\tutorial-from-scripts-to-serenity\node_modules\ts-node\src\index.ts:406:44)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) [as .ts] (C:\src\js\tutorial-from-scripts-to-serenity\node_modules\ts-node\src\index.ts:409:12)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)

It appears that either "chai as promises" isn't being setup properly or there is a typescript issue.

using node 6.10 and npm 4.4.1.

Am I missing something obvious?

@jan-molak
Copy link
Member

Thanks for reporting this, that's interesting.

Are you seeing this problem on a fresh copy of 2-reports?

@marktigno
Copy link

Actually I'm also experiencing the same error when I'm creating my scripts using Screenplay pattern. I just follow what is instructed on the tutorial but that TSError (2339) always appearing.

@jan-molak
Copy link
Member

jan-molak commented Mar 14, 2017

Sorry to hear that, what platform are you on? OS/node version?

Also, @johnlister and @marktigno would you be able to push a code sample to github so that I can try to reproduce the problem?

I think this might be caused by the @types/chai-as-promised not getting loaded for some reason.

@marktigno
Copy link

marktigno commented Mar 14, 2017

@jan-molak Here's what I used on my machine:
OS: Windows 10
Node: 6

I used npm manager to pull a fresh copy of the packages, but the problem is on the chai-as-promise part where it says the "eventually" is not recognized as part of 'Assertion'. I check the exports from the 'expect.ts' file on the sample project to see if the references are properly set, but it seems there is something missing on it.

@johnlister
Copy link
Author

Windows 10, fresh install of Node 6.10, updated to latest NPM (4.4). clone the tutorial and switch to "2-reports" branch
npm install followed by npm test. This is with unmodified code in the branch.

I haven't installed any npm modules globally - oddly visual studio code doesn't complain about eventually, but does note that expect returns the base Assertion class and not a PromiseAssertion. I'm reasonably new to typescript, but is this a types issue in how it interprets the response of expect?

@marktigno
Copy link

Here's my sample screenshot:

image

@jan-molak
Copy link
Member

jan-molak commented Mar 14, 2017

I see what you mean, but I'm not able to reproduce the issue on a MacOS and don't have access to a Windows machine at the moment. There are several things at play here, so maybe this will help you find out more about the root cause of the problem:

For chai-as-promised to work with chai, we need to:

  • register it
  • but we also need to make the IDE aware of the type definitions (as far as IntelliJ or VisualStudio are concerned, it's still regular Chai that they're providing intelli-sense for, that's why they complain about the property not being there)

My IntelliJ is configured to use the local TypeScript module and the tsconfig.json file that ships with the tutorial:
screen shot 2017-03-14 at 16 46 38

I'm guessing that VS might need similar sort of configuration.

Perhaps VS has a setting to enable TypeScript language service?

@johnlister
Copy link
Author

johnlister commented Mar 14, 2017

Visual Studio Code seems to work fine, it seems to be the just in time compilation when it loads the web page or test within? I only used VS code to load the project just to see if it gave me any clues. The error happens when I run "npm test".

One other thing, I can see in the transpiled javascript the files from screenplay, but not in features?

@marktigno
Copy link

I did a little play around on the "node_modules/@types/chai/index.d.ts" and place the line "eventually: Assertion;". Now it recognized the keyword but it gives now a different error shown here:

capture

@marktigno
Copy link

marktigno commented Mar 15, 2017

I found the solution here:
jan-molak/serenity-js-fast-track-demo@1b545fa

@johnlister
Copy link
Author

Perfect, works for me. Oddly google didn't bring that up, but I did spot something similar in another project. I incorrectly assumed that both forms were identical in function - clearly not.

jan-molak added a commit to serenity-js/tutorial-from-scripts-to-serenity that referenced this issue Mar 19, 2017
@jan-molak
Copy link
Member

Hey @johnlister @marktigno, I've just updated the tutorial, would you mind checking if that helps to solve the problem you noticed?

@marktigno
Copy link

@jan-molak will do, I'll apply the latest updates on my local machine and verify the fix.

@marktigno
Copy link

Hello @jan-molak, I've verified the fix and now it's working. However there's a separate issue when running the test. It seems it's getting a timeout issue after it's launch. But I've made another fix on it so it won't happened again.

helpers-1

helpers-2

Thanks! :)

@jan-molak
Copy link
Member

No problem at all! The todomvc.com website can be slow at times, so setting the timeout will definitely help :-)

jan-molak added a commit to serenity-js/tutorial-from-scripts-to-serenity that referenced this issue Mar 20, 2017
@johnlister
Copy link
Author

johnlister commented Mar 20, 2017

Hi, the fix you've put in place works, but there is an issue on the dependency of gherkin. It now fetches v4.1.1 of gherkin (via cucumber) which when I run it causes the following issue:

E/launcher - Error: TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.relative (path.js:539:5)
    at C:\src\js\serenity-js-e2e-testing-sample\node_modules\serenity-js\src\serenity\reporting\serenity_bdd_reporter.ts:89:38

Forcing gherkin to be v4.0.0 works - it looks like the only difference is gherkin has updated to using node 7 - I suspect the path api has changed as I'm currently running node 6.10

@jan-molak
Copy link
Member

Thanks @johnlister, @metrophos has just raised that under #32

jan-molak added a commit that referenced this issue Mar 20, 2017
…rrectly on Windows

affects: serenity-js

ISSUES CLOSED: #30
@marktigno
Copy link

Hello @jan-molak!
I've updated the package.json based on what is posted on issue #32 and it works perfectly. Thanks!

@jan-molak
Copy link
Member

Perfect, thanks for the update :-)

@rollrodrig
Copy link

rollrodrig commented Apr 25, 2019

I am trying to use Chai Promise test but it show an error
I am using docker.

Here a simple function

			let funcPromise = (n) => {
			    return new Promise((resolve, reject) =>{
			        if(n=="a") {
			            resolve("success");
			        }else {
			            reject("Fail")
			        }
			    })
			}

simple test

			import chai from 'chai';
			var chaiAsPromised = require('chai-as-promised');
			chai.use(chaiAsPromised);
			let expect = chai.expect;
			let assert = chai.assert;				

			it('connect: test promise', (done) => {
				let func = funcPromise("a");
				expect(func).to.eventually.equal("success"); // dont work
				expect(func).to.be.rejected; // dont work
			})

Error on terminal
FileTest.spec.ts:43:25 - error TS2339: Property 'eventually' does not exist on type 'Assertion'.

storage/database/MongooseEngine.spec.ts:44:35 - error TS2339: Property 'rejected' does not exist on type 'Assertion'.

@jan-molak
Copy link
Member

Hi @rollrodrig,

At first glance, the reason behind the compiler error seems to be the mixup of different import styles.

Instead of saying:

import chai from 'chai';
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
let expect = chai.expect;
let assert = chai.assert;

Try:

import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

const expect = chai.expect;

The var chaiAsPromised = require('chai-as-promised') syntax tells the compiler that the module in question does not have any type definitions. Because of that, chai-as-promised types are never registered, and the compiler correctly complains that Property 'eventually' does not exist on type 'Assertion', as both eventually and rejected are defined in the chai-as-promised module which has been ignored.

Hope this helps!
Jan

@rollrodrig
Copy link

Hi @rollrodrig,

At first glance, the reason behind the compiler error seems to be the mixup of different import styles.

Instead of saying:

import chai from 'chai';
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
let expect = chai.expect;
let assert = chai.assert;

Try:

import chai = require('chai');
import chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

const expect = chai.expect;

The var chaiAsPromised = require('chai-as-promised') syntax tells the compiler that the module in question does not have any type definitions. Because of that, chai-as-promised types are never registered, and the compiler correctly complains that Property 'eventually' does not exist on type 'Assertion', as both eventually and rejected are defined in the chai-as-promised module which has been ignored.

Hope this helps!
Jan

Thanks !!
Finally i solved the problem.
I would like to share the link.
https://stackoverflow.com/a/55855503/5708097

@jan-molak
Copy link
Member

Cool, glad we could help 👍

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

4 participants