CodeSequence / jasmine-marbles

Marble testing helpers for RxJS and Jasmine
MIT License
116 stars 39 forks source link

Rework of matcher to have a better error output and no lodash dependency #50

Closed xileftenurb closed 4 years ago

xileftenurb commented 4 years ago

Hi here,

I wanted a better error output, so I modified the matcher for my own use.

Feel free to pull my version if you want. the issues I fixed :

brandonroberts commented 4 years ago

Hi @xileftenurb, will you show examples of what the new output looks like compared to the old?

xileftenurb commented 4 years ago

good point, here is some real example of a test I'm working on right now

Failed: 
Expected :
    {"frame":0,"notification":{"kind":"N","value":"
        {}
    ","hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":"
        {}
    ","hasValue":true}}
    {"frame":16,"notification":{"kind":"N","value":"
        {}
    ","hasValue":true}}
    {"frame":20,"notification":{"kind":"N","value":"
        {"sort":"-name"}
    ","hasValue":true}}
    {"frame":23,"notification":{"kind":"N","value":"
        {"sort":"name"}
    ","hasValue":true}}
to deep equal :
    {"frame":0,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":"
        {}
    ","hasValue":true}}
    {"frame":16,"notification":{"kind":"N","value":"
        {}
    ","hasValue":true}}
    {"frame":20,"notification":{"kind":"N","value":"
        {"sort":"-name"}
    ","hasValue":true}}
    {"frame":23,"notification":{"kind":"N","value":"
        {"sort":"name"}
    ","hasValue":true}}

Marble :
actual   : 1---------1-----1---2--3
expected : 4---------1-----1---2--3
value :
{
    1 : "{}"
    2 : "{\"sort\":\"-name\"}"
    3 : "{\"sort\":\"name\"}"
    4 : "null"
}
xileftenurb commented 4 years ago

with the new commit, the output look like this :

Failed: 
Expected :
    {"frame":5,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":5,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":5,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":5,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":22,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":22,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":22,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":22,"notification":{"kind":"N","value":null,"hasValue":true}}
to deep equal :
    {"frame":5,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":10,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":18,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":22,"notification":{"kind":"N","value":null,"hasValue":true}}
    {"frame":30,"notification":{"kind":"N","value":null,"hasValue":true}}

Marble :
actual   : -----(1111)----(1111) 7ms ----(1111) 7ms - 
expected : -----1     ----1      7ms 1---1      7ms 1
value :
{
    1 : "null"
}

Also, the build fail because I added "2019" in the lib, and the config seem to not like that. Is it fixable? I could always add a polyfill for flatMap, but since we use typescript, that look silly to me.

krzysztof-grzybek commented 4 years ago

@xileftenurb I pulled your changes, and after fixes needed to build it properly, I didn't see any difference between error reporting. How do You use this library? I use it like this:

expect(myObservable$).toBeObservable(cold('a', { a: true }));

It seems that it's implementation is defined here.

xileftenurb commented 4 years ago

@krzysztof-grzybek I'm not very used to build system, I used it like this :

import {getTestScheduler} from "jasmines-marbles"
const scheduler = new getTestScheduler()
scheduler.run(helper => {
   helper.expectObservable(myObservable$).toBe("a", {a : true});
})
krzysztof-grzybek commented 4 years ago

@xileftenurb I see. I'm afraid it's not the usage which the library was designed for. Take a look here.

brandonroberts commented 4 years ago

Closed by #55