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

Is there any ideas how to make custom values working correctly? #311

Closed
sharikovvladislav opened this issue Dec 17, 2019 · 2 comments
Closed

Comments

@sharikovvladislav
Copy link

sharikovvladislav commented Dec 17, 2019

Hi!

Thank you for the tool. Thats really cool. I want to use it because of beautiful expected / actual output.

Is there any possibility to add support of custom values?

Example:

  const values = { a: 1, b: 2, x: 2, y: 4, t: true, f: false };
  const source = hot('---a--bt--|', values);
  const expected = e('---x--yf---|', values);
  // ...

You will get this as a result:

        "Source:   ---2--4ä--|"
        "Expected: ---2--4ä---|"

Is there any possibility to make it:

        "Source:   ---x--yt--|"
        "Expected: ---x--yf---|"

?

Looks like API retrieves all information to make it possible. Looks like you don't even need to change / improve API to achieve this.

@kwonoj
Copy link
Owner

kwonoj commented Dec 17, 2019

I don't think you can do this out of box, looks like you'd like to resolve marble to key but currently always falls to value to draw marbles. Main design comes due to key for marble observable is arbitrary value, actual value we care about is value itself (if key === value that doesn't matter though). Not sure if I'll spend time to create additional path for this logic.

@kwonoj kwonoj closed this as completed Dec 17, 2019
@sharikovvladislav
Copy link
Author

Main design comes due to key for marble observable is arbitrary value, actual value we care about is value itself (if key === value that doesn't matter though)

Thats perfect. But at the moment if you put null/undefined to the observable , you will get some stuff like ä as the output. Yeah, okay, and what is ä? What are other symbols? You don't know it at all from the output. Just debug.

Okay, so now the library works perfectly only with numbers and values which are 1-literal strings.

The test:

it('testcase', () => {
  const {hot, e, s, getMessages, flush} = rxSandbox.create();


  const values = { a: undefined };
  const source = hot('aaaaaaaaa|', values);
  const expected = e('---x--yf---|', values);
  
  const messages = getMessages(source.pipe(mapTo(undefined)));
  flush();

  marbleAssert(messages).to.equal(expected);
});

Output:

        Error: 
        "Source:   äḅċḋëḟġḧï|"
        "Expected: ---x--yf---|"

It is simple observable which emits undefined N times. Cool. And we got äḅċḋëḟġḧï| as output. Well, that makes sense. Developer experience.

Main design comes...

Values in the observables in test are not random. You write test, you pass test data, you know what values you will pass and what values are expected. That is how unit testing works.
Even some kind of fn as value can be passed, when you will determine symbol based on some logic (complex objects, you can use type guards).

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

2 participants