Coder Social home page Coder Social logo

condition for expectJSONTypes about frisby HOT 4 CLOSED

vlucas avatar vlucas commented on July 25, 2024
condition for expectJSONTypes

from frisby.

Comments (4)

cjsaylor avatar cjsaylor commented on July 25, 2024

I think you can do something like:

expectJSONType([{
  district_id: function(val) {
    expect(val).toBeGreaterThan(0)
  },
  district_name: String
}])

As for the response being empty, you would just do a separate test that you know will produce an empty array, and do:

expectJSON([])

from frisby.

vlucas avatar vlucas commented on July 25, 2024

Beat me to it :)

Yes, you can do custom callbacks with your own Jasmine matchers in place of the normal String, Number, Boolean, etc. The only other thing to note is that you may want to return the result of the custom expectation inside your callback, depending on what error message you want to see.

from frisby.

Shplorf avatar Shplorf commented on July 25, 2024

Passing [] to expectJSON always passes for me as long as it's an array. I'm trying to figure out how to encode into the JSON that I'm specifically expecting ONLY an empty array.

from frisby.

jatinst avatar jatinst commented on July 25, 2024

I am having the same issue as @Shplorf . I am using expectJSONLength(0) for now which is working. But it's weird that expectJSON([]) always passes!

from frisby.

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.