Code Monkey home page Code Monkey logo

Comments (9)

mikearnaldi avatar mikearnaldi commented on July 21, 2024 1

vitest-dev/vitest#5620

from effect.

sukovanej avatar sukovanej commented on July 21, 2024

Started playing with it in the effect codebase and seems like the expect(<option>).toStrictEqual(<another option>) always succeeds independently of what are the option values, for example this succeeds in the test/Option.test.ts

    expect(_.some(1)).toStrictEqual(_.some(2))
    expect(_.none()).toStrictEqual(_.some(2))

from effect.

sukovanej avatar sukovanej commented on July 21, 2024

Okay, seems to be the Symbol.iterator that makes the difference - which makes sense, that is the thing introduced in 3.0.4 to enable to yield without an adapter, right?

  [Symbol.iterator]() {
    return new SingleShotGen.SingleShotGen(this) as any
  },

When I remove it from the Effect prototype the comparison starts working. cc @mikearnaldi

from effect.

mikearnaldi avatar mikearnaldi commented on July 21, 2024

Yup that comes from 3.0.4, I don't see how this could ever be considered a bug of effect, it's behaviour of expect...

from effect.

mikearnaldi avatar mikearnaldi commented on July 21, 2024

The Effect way of comparing options is Equals.equals(a, b)

from effect.

sukovanej avatar sukovanej commented on July 21, 2024

In this codebase you rely on the expect().toStrictEqual() / Util.deepStrictEqual etc checks in the tests as well. Therefore, from 3.0.4, tests in here doing checks on options actually test nothing because they all always succeed. And this will apply for all the consumers of effect lib as well.

from effect.

mikearnaldi avatar mikearnaldi commented on July 21, 2024

Yeah but that's a bug in expect not in Effect... like I am trying to compare two objects with a[Symbol.iterator] = [1, 2, 3, Math.random()][Symbol.iterator] and it says that they are equal, why on earth???

from effect.

mikearnaldi avatar mikearnaldi commented on July 21, 2024

seems like a vitest issue, jest had a similar jestjs/jest#8280

from effect.

mikearnaldi avatar mikearnaldi commented on July 21, 2024

The following works:

import { jestExpect as expect } from "@jest/expect"
import { describe, it } from "vitest"

describe("Vitest Issue", () => {
  it("compares", () => {
    const a = {
      value: 0,
      [Symbol.iterator]: [0, 1, 2, Math.random()][Symbol.iterator]
    }
    const b = {
      value: 1,
      [Symbol.iterator]: [0, 1, 2, Math.random()][Symbol.iterator]
    }
    expect(a).toStrictEqual(b)
  })
})

from effect.

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.