Giter Site home page Giter Site logo

Comments (23)

jan-molak avatar jan-molak commented on May 22, 2024 2

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?

from serenity-js.

johnlister avatar johnlister commented on May 22, 2024 1

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?

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024 1

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

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024 1

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

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024 1

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! :)

from serenity-js.

rollrodrig avatar rollrodrig commented on May 22, 2024 1

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

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

Thanks for reporting this, that's interesting.

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

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

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.

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

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.

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

@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.

from serenity-js.

johnlister avatar johnlister commented on May 22, 2024

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?

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

Here's my sample screenshot:

image

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

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

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

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

from serenity-js.

johnlister avatar johnlister commented on May 22, 2024

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.

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

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

from serenity-js.

johnlister avatar johnlister commented on May 22, 2024

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

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

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

from serenity-js.

marktigno avatar marktigno commented on May 22, 2024

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

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

Perfect, thanks for the update :-)

from serenity-js.

rollrodrig avatar rollrodrig commented on May 22, 2024

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'.

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

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

from serenity-js.

jan-molak avatar jan-molak commented on May 22, 2024

Cool, glad we could help 👍

from serenity-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.