avrelian / jasmine2-custom-message

custom failure message on any jasmine v2 assertion
MIT License
27 stars 6 forks source link

How to use it in typescript #18

Closed NicoForce closed 5 years ago

NicoForce commented 5 years ago

Greetings,

This is not exactly an issue, but I can't seem to find a typescript sample.

Since I'm having trouble importing it and using it I wanted to ask how to in here.

I use:

jasmine 2.8.12 typescript 3.1.6

HolgerJeromin commented 5 years ago

I include the .d.ts files in my tsconfig.json, but your setup could be different:

  "include": [
    "Lib/jasmine.d.ts",
    "Lib/jasmine2-custom-message.d.ts",

The .d.ts file is in this repository. After that Typescript knows this jasmine plugin:

                since('Expected the day to be #{expected}, but got #{actual}').
                    expect(result.day).toBe(2);

I add jasmine2-custom-message.js the same way as my own compiled js files into my test system (karma in my case).

NicoForce commented 5 years ago

I also have added the d.ts files inside my tsconfig.json but it's not working :(, the library works when I do a javascript import; however, that's not what I'm trying to accomplish.

HolgerJeromin commented 5 years ago

Can you share us a minimal project for reproducing this issue? Otherwise helping you would be not easy.

NicoForce commented 5 years ago

I just noticed I was importing it wrong, and by just adding this line:

import 'jasmine2-custom-message';

I was able to start using the since keyword.

I was able to use the since without importing, even by doing proper configuration in a clean project by adding the following to tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "moduleResolution": "node",
    "sourceMap": false,
    "declaration": false,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "testsJs",
    "typeRoots": [ "./node_modules/@types",
      "./node_modules/jasmine2-custom-message"],
    "types": ["jasmine", "jasmine2-custom-message"]
  },
  "exclude": [
    "node_modules"
  ]
} 

However, in my project, only importing works. Adding the above mentioned configuration to the tsconfig.json doesn't work. :(

HolgerJeromin commented 5 years ago

@NicoForce Have you tried to add jasmine2-custom-message.d.ts to the include part of tsconfig.json? Your example uses types not include

NicoForce commented 5 years ago

I'm sorry I kept this issue open for so long, I wasn't able to try with include since the key words include and exclude are mutually exclusive.

Nonetheless, I managed to get it working somehow as I explained in my last message.