debitoor / chai-subset

"containSubset" object properties matcher for Chai
http://chaijs.com/plugins/chai-subset/
MIT License
82 stars 20 forks source link

URL support? #60

Open stevenvachon opened 7 years ago

stevenvachon commented 7 years ago
const {URL} = require("url");
const url1 = "http://domain1/";
const url2 = "http://domain2/";

expect( new URL(url1) ).to.containSubset( new URL(url2) );
expect({ key:new URL(url1) }).to.containSubset({ key:new URL(url2) });

// none throw when both should

This works, however:

expect( new URL(url1) ).to.containSubset({ href:url1 });
expect( new URL(url1) ).to.not.containSubset({ href:url2 });
expect({ key:new URL(url1) }).to.containSubset({ key:{ href:url1 } });
expect({ key:new URL(url1) }).to.not.containSubset({ key:{ href:url2 } });
stevenvachon commented 7 years ago

I'm not sure how to PR this, as detecting a URL would require a dependency:

const isURL = require('isurl');

if (isURL.lenient(expected)) {
    if (isURL.lenient(actual)) {
        return expected.href === actual.href;
    } else {
        return false;
    }
}

... and this lib has been written as a UMD module.

eagleeye commented 7 years ago

This module is not going to support any non-standard objects. Since you can do a workaround - please do a workaround or create separate module.

stevenvachon commented 7 years ago

Non-standard?

https://url.spec.whatwg.org https://developer.mozilla.org/en/docs/Web/API/URL

This module supports Date, which is no more standard than URL.

eagleeye commented 7 years ago

you are right, didn't noticed that there is a standart URL object. I'll keep this issue open, until I'll find some good clues, what to do with this

stevenvachon commented 7 years ago

I have written isurl, which works cross-realm -- something that this module's Date check should also do in order to support Worker and Node's cluster. But I'm not sure how to get dependencies in without adding a build step since this module is UMD.

stevenvachon commented 7 years ago

You can probably just copy what is being done here: https://github.com/JamesMGreene/chai-deep-match/issues/2#issuecomment-297527973

JamesMGreene commented 7 years ago

It may have a standard but, as I mention many times in https://github.com/JamesMGreene/chai-deep-match/issues/2, I find it to be extremely un-semantic. 👎

stevenvachon commented 7 years ago

@JamesMGreene it's an evolving standard. Feel free to assert your thoughts: https://github.com/whatwg/url/issues

JamesMGreene commented 7 years ago

@stevenvachon: Thanks for the info, I will.

stevenvachon commented 5 years ago

Any update?