Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

.deep.property('https://schema.org/mentions[0]') is not resolved #398

Closed
thom4parisot opened this issue Mar 10, 2015 · 4 comments
Closed

Comments

@thom4parisot
Copy link

I have the following object structure:

{
  "https://schema.org/mentions": [
    "http://dbpedia.org/resource/London_Daily_News",
    "http://dbpedia.org/resource/Jonathan_Aitken"
  ]
}

I then run the following assertion:

expect(dataStructure).to.have.deep.property('https://schema.org/mentions[0]', 'http://dbpedia.org/resource/London_Daily_News');

An exception is raised:

AssertionError: expected { Object (https://schema.org/mentions) } to have key 'https://schema.org/mentions'

If I change the https://schema.org/mentions key to mentions only, the assertion works.

@keithamus
Copy link
Member

Hi @oncletom thanks for the issue.

deep.property allows for object syntax which means using . and [] syntaxes to get into properties.

Using a URL is not compatible as URLs have .s in them. So your lookup is broken down into:

['https://schema', 'org/mentions', 0]

We could attempt to implement escaping of the control characters (./[/]), probably using a \ but this feels messy, you should probably just avoid using .deep for these circumstances - so your assertion could become:

expect(dataStructure).to.have.property('https://schema.org/mentions').have.property(0, 'http://dbpedia.org/resource/London_Daily_News');

I'm going to close this issue - as I feel like the above will solve your problem. If you still really want to use .deep.property - please file a new issue about escaping control characters in deep property, and we can have a full discussion about it there.

If you have any problems further to this issue, feel free to comment here or raise a new issue.

@thom4parisot
Copy link
Author

Thanks for your feedback. This is how I ended up anyway. I just was not sure if I did something wrong or not.

So 👍

@keithamus
Copy link
Member

Hey @oncletom I've got some good news! #402 enabled escaping of .deep.properties, so you can now do:

expect(dataStructure).to.have.deep.property('https://schema\\.org/mentions[0]', 'http://dbpedia.org/resource/London_Daily_News')

@thom4parisot
Copy link
Author

You rock @keithamus :-) thanks for the follow-up!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants