expect(false).toBe(true, "it's true") doesn't print "it's true" in the console output. How did the expected and received become the emails? It accepts an array of custom equality testers as a third argument. By clicking Sign up for GitHub, you agree to our terms of service and If you keep the declaration in a .d.ts file, make sure that it is included in the program and that it is a valid module, i.e. You can use it instead of a literal value: expect.not.arrayContaining(array) matches a received array which does not contain all of the elements in the expected array. Other times, however, a test author may want to allow for some flexibility in their test, and toBeWithinRange may be a more appropriate assertion. SHARE. You can match properties against values or against matchers. If the promise is rejected the assertion fails. For example, to assert whether or not elements are the same instance: Use .toHaveBeenCalledWith to ensure that a mock function was called with specific arguments. This caused the error I was getting. Next, move into the src directory and create a new file named formvalidation.component.js. Id argue, however, that those are the scenarios that need to be tested just as much if not more than when everything goes according to plan, because if our applications crash when errors happen, where does that leave our users? Let's use an example matcher to illustrate the usage of them. For example, let's say you have a drinkFlavor function that throws whenever the flavor is 'octopus', and is coded like this: The test for this function will look this way: And it will generate the following snapshot: Check out React Tree Snapshot Testing for more information on snapshot testing. www.npmjs.com/package/jest-expect-message. 'does not drink something octopus-flavoured', 'registration applies correctly to orange La Croix', 'applying to all flavors does mango last', // Object containing house features to be tested, // Deep referencing using an array containing the keyPath, 'livingroom.amenities[0].couch[0][1].dimensions[0]', // Referencing keys with dot in the key itself, 'drinking La Croix does not lead to errors', 'drinking La Croix leads to having thirst info', 'the best drink for octopus flavor is undefined', 'the number of elements must match exactly', '.toMatchObject is called for each elements, so extra object properties are okay', // Test that the error message says "yuck" somewhere: these are equivalent, // Test that we get a DisgustingFlavorError, 'map calls its argument with a non-null argument', 'randocall calls its callback with a class instance', 'randocall calls its callback with a number', 'matches even if received contains additional elements', 'does not match if received does not contain expected elements', 'Beware of a misunderstanding! Especially when you have expectations in loops, this functionality is really important. Is this supported in jest? Stack Overflow, Print message on expect() assert failure Stack Overflow. This is especially useful for checking arrays or strings size. Write Unit Tests with Jest in Node.js. These helper functions and properties can be found on this inside a custom tester: This is a deep-equality function that will return true if two objects have the same values (recursively). 2. For example, take a look at the implementation for the toBe matcher: When an assertion fails, the error message should give as much signal as necessary to the user so they can resolve their issue quickly. For a generic Jest Message extender which can fit whatever Jest matching you'd already be able to use and then add a little bit of flourish: For specific look inside the expect(actualObject).toBe() in case that helps your use case: you can use this: (you can define it inside the test). Instead of importing toBeWithinRange module to the test file, you can enable the matcher for all tests by moving the expect.extend call to a setupFilesAfterEnv script: expect.extend also supports async matchers. Well occasionally send you account related emails. If a promise doesn't resolve at all, this error might be thrown: Most commonly this is being caused by conflicting Promise implementations. When using yarn jest the root jest config is used as well as the package config, but the "reporters" option is only read from the root one (not sure why). For example, let's say that we have a few functions that all deal with state. For checking deeply nested properties in an object you may use dot notation or an array containing the keyPath for deep references. You can write: Also under the alias: .toReturnWith(value). toHaveProperty will already give very readable error messages. Issue #3293 - GitHub, How to add custom message to Jest expect? Book about a good dark lord, think "not Sauron". Does With(NoLock) help with query performance? This will have our form component with validation. You can test this with: This matcher also accepts a string, which it will try to match: Use .toMatchObject to check that a JavaScript object matches a subset of the properties of an object. . Going through jest documentation again I realized I was directly calling (invoking) the function within the expect block, which is not right. So when using yarn jest filepath, the root jest config was used but not applying my custom reporter as the base config is not imported in that one. Did you notice the change in the first test? To learn more, see our tips on writing great answers. You can use it inside toEqual or toBeCalledWith instead of a literal value. That is, the expected object is not a subset of the received object. See for help. Bryan Ye. If you are using your own custom transformer, consider adding a getCacheKey function to it: getCacheKey in Relay. # Testing the Custom Event message-clicked is emitted We've tested that the click method calls it's handler, but we haven't tested that the handler emits the message-clicked event itself. You can provide an optional argument to test that a specific error is thrown: For example, let's say that drinkFlavor is coded like this: We could test this error gets thrown in several ways: Use .toThrowErrorMatchingSnapshot to test that a function throws an error matching the most recent snapshot when it is called. If a law is new but its interpretation is vague, can the courts directly ask the drafters the intent and official interpretation of their law? Making statements based on opinion; back them up with references or personal experience. For example, let's say you have some application code that looks like: You may not care what thirstInfo returns, specifically - it might return true or a complex object, and your code would still work. Therefore, it matches a received object which contains properties that are present in the expected object. A great place where you can stay up to date with community calls and interact with the speakers. When Jest executes the test that contains the debugger statement, execution will pause and you can examine the current scope and call stack. Use .toHaveLastReturnedWith to test the specific value that a mock function last returned. The most useful ones are matcherHint, printExpected and printReceived to format the error messages nicely. Instead of using the value, I pass in a tuple with a descriptive label. Learn more. You can call expect.addSnapshotSerializer to add a module that formats application-specific data structures. Jest is great for validation because it comes bundled with tools that make writing tests more manageable. a class instance with fields. JavaScript in Plain English. It is described in Jest docs here, but it is not really obvious. For example, if you want to check that a function fetchNewFlavorIdea() returns something, you can write: You could write expect(fetchNewFlavorIdea()).not.toBe(undefined), but it's better practice to avoid referring to undefined directly in your code. It optionally takes a list of custom equality testers to apply to the deep equality checks (see this.customTesters below). One more example of using our own matchers. Instead of literal property values in the expected object, you can use matchers, expect.anything(), and so on. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time. This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. exports[`stores only 10 characters: toMatchTrimmedSnapshot 1`] = `"extra long"`; expect('extra long string oh my gerd').toMatchTrimmedInlineSnapshot(, // The error (and its stacktrace) must be created before any `await`. I found one way (probably there are another ones, please share in comments) how to display custom errors. This issue has been automatically locked since there has not been any recent activity after it was closed. JEST: Display custom errors and check for an immutability | by Yuri Drabik | Medium Write Sign up 500 Apologies, but something went wrong on our end. While Jest is easy to get started with, its focus on simplicity is deceptive: jest caters to so many different needs that it offers almost too many ways to test, and while its documentation is extensive, it isnt always easy for an average Jest user (like myself) to find the answer he/she needs in the copious amounts of examples present. While automated tests like unit and integration tests are considered standard best-practices, we still have a tendency, even during testing, to only cover the happy paths (the paths where all the API calls return, all the data exists, all the functions work as expected), and ignore the sad paths (the paths where outside services are down, where data doesnt exist, where errors happen). Has 90% of ice around Antarctica disappeared in less than a decade? Another thing you can do is use the shard flag to parallelize the test run across multiple machines. Better Humans. This example also shows how you can nest multiple asymmetric matchers, with expect.stringMatching inside the expect.arrayContaining. For example, defining how to check if two Volume objects are equal for all matchers would be a good custom equality tester. Jest provides the expect.extend () API to implement both custom symmetric and asymmetric matchers. Next: Still no luck. Contrary to what you might expect, theres not a lot of examples or tutorials demonstrating how to expect asynchronous errors to happen (especially with code employing the newer ES6 async/await syntax). It calls Object.is to compare primitive values, which is even better for testing than === strict equality operator. Alternatively, you can use async/await in combination with .rejects. !, an answer was found, buried deep in Jests documentation among the Async Examples in the guides. Based on the findings, one way to mitigate this issue and improve the speed by up to 50% is to run tests sequentially. So it took me some time to figure it out. You can write: Also under the alias: .toReturnTimes(number). to your account. The message should be included in the response somehow. prepareState calls a callback with a state object, validateState runs on that state object, and waitOnState returns a promise that waits until all prepareState callbacks complete. If you have floating point numbers, try .toBeCloseTo instead. expect.anything() matches anything but null or undefined. You should craft a precise failure message to make sure users of your custom assertions have a good developer experience. We try to handle those errors gracefully so the application can continue to run, so our users can do what they came there to do and so we test: automated tests, manual tests, load tests, performance tests, smoke tests, chaos tests. Use it.each(yourArray) instead (which is valid since early 2020 at least). There are a lot of different matcher functions, documented below, to help you test different things. Use .toBeTruthy when you don't care what a value is and you want to ensure a value is true in a boolean context. Refresh the page, check Medium 's site status, or find something. it('fails with a custom error message', async (done) => { try { await expect(somePromise()).resolves.toMatchObject({foo: 'bar' }) done() } catch(error) { throw new Error(` $ {error} Write a helpful error message here. I search for it in jestjs.io and it does not seem to be a jest api. The solution First, you need to know that Jest's `expect`-function throws an error when things don't turn out as expected. In our case it's a helpful error message for dummies new contributors. Love JavaScript? is there a chinese version of ex. Use assert instead of expect is the current workaround if you really need it. test(should throw an error if called without an arg, () => {, test(should throw an error if called without a number, () => {. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. For example, test that ouncesPerCan() returns a value of at least 12 ounces: Use toBeLessThan to compare received < expected for number or big integer values. For example, let's say you have a mock drink that returns the name of the beverage that was consumed. We had it tell us the actual difference, in seconds, between the time we expected and the time we got. @cpojer is there a way to produce custom error messages? So if you want to test that thirstInfo will be truthy after drinking some La Croix, you could write: Use .toBeUndefined to check that a variable is undefined. For example, let's say that we have a function doAsync that receives two callbacks callback1 and callback2, it will asynchronously call both of them in an unknown order. Try using the debugging support built into Node. Are you sure you want to create this branch? Why did the Soviets not shoot down US spy satellites during the Cold War? Still (migrating from mocha), it does seem quite inconvenient not to be able to pass a string in as a prefix or suffix. It's especially bad when it's something like expected "true", got "false". Note that we are overriding a base method out of the ResponseEntityExceptionHandler and providing our own custom implementation. How To Wake Up at 5 A.M. Every Day. it enables autocompletion in IDEs, // `floor` and `ceiling` get types from the line above, // it is recommended to type them as `unknown` and to validate the values, // `this` context will have correct typings, // remember to export `toBeWithinRange` as well, // eslint-disable-next-line prefer-template. Errors and bugs are a fact of life when it comes to software development, and tests help us anticipate and avoid at least some if not all of those errors but only when we actually take the time to test those sad path scenarios. You try this lib that extends jest: https://github.com/mattphillips/jest-expect-message. privacy statement. This too, seemed like it should work, in theory. 1 Your error is a common http error, it has been thrown by got not by your server logic. To learn more, see our tips on writing great answers. pass indicates whether there was a match or not, and message provides a function with no arguments that returns an error message in case of failure. @cpojer @SimenB I get that it's not possible to add a message as a last param for every assertion. Use Git or checkout with SVN using the web URL. That's not always going to be the case. You can also throw an error following way, without using expect(): It comes handy if you have to deal with a real async code, like bellow: When you have promises, it's highly recommended to return them. rev2023.3.1.43269. > 2 | expect(1 + 1, 'Woah this should be 2! Asking for help, clarification, or responding to other answers. Asking for help, clarification, or responding to other answers. .toBeNull() is the same as .toBe(null) but the error messages are a bit nicer. .toEqual won't perform a deep equality check for two errors. Theoretically Correct vs Practical Notation, Retrieve the current price of a ERC20 token from uniswap v2 router using web3js. Do you want to request a feature or report a bug? In Chai it was possible to do with second parameter like expect(value, 'custom fail message').to.be and in Jasmine seems like it's done with .because clause. Can we reduce the scope of this request to only toBe and toEqual, and from there consider (or not consider) other assertion types? You can use expect.addEqualityTesters to add your own methods to test if two objects are equal. You can write: Also under the alias: .nthCalledWith(nthCall, arg1, arg2, ). Refresh the page, check Medium 's site status, or find something interesting to read. Use .toContain when you want to check that an item is in an array. Try running Jest with --no-watchman or set the watchman configuration option to false. For example you could create a toBeValid(validator) matcher: Note: toBeValid returns a message for both cases (success and failure), because it allows you to use .not. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. When you're writing tests, you often need to check that values meet certain conditions. Let me know what your thoughts are, perhaps there could be another way to achieve this same goal. Jest's configuration can be defined in the package.json file of your project, or through a jest.config.js, or jest.config.ts file or through the --config <path/to/file.js|ts|cjs|mjs|json> option. For example, let's say that you're testing a number utility library and you're frequently asserting that numbers appear within particular ranges of other numbers. Custom matchers are good to use when you want to provide a custom assertion that test authors can use in their tests. Built with Docusaurus. If, after the validateUploadedFile() function is called in the test, the setUploadedError() function is mocked to respond: And the setInvalidImportInfo() function is called and returned with: According to the jest documentation, mocking bad results from the functions seemed like it should have worked, but it didnt. Solution is to do JSON.parse(resError.response.body)['message']. For example, if you want to check that a function bestDrinkForFlavor(flavor) returns undefined for the 'octopus' flavor, because there is no good octopus-flavored drink: You could write expect(bestDrinkForFlavor('octopus')).toBe(undefined), but it's better practice to avoid referring to undefined directly in your code. Thatll be it for now. When you're writing tests, you often need to check that values meet certain conditions. It's important to remember that expect will set your first parameter (the one that goes into expect(akaThisThing) as the first parameter of your custom function. 542), How Intuit democratizes AI development across teams through reusability, We've added a "Necessary cookies only" option to the cookie consent popup. No point in continuing the test. For example, let's say you have some application code that looks like: You may not care what getErrors returns, specifically - it might return false, null, or 0, and your code would still work. toEqual is a matcher. It's easier to understand this with an example. Retry with --no-cache. The test will fail with the corresponding message depending on whether you want it to pass the validation. You can also pass an array of objects, in which case the method will return true only if each object in the received array matches (in the toMatchObject sense described above) the corresponding object in the expected array. Connect and share knowledge within a single location that is structured and easy to search. Would the reflected sun's radiation melt ice in LEO? Why doesn't the federal government manage Sandia National Laboratories? It is recommended to use the .toThrow matcher for testing against errors. Please note this issue tracker is not a help forum. The expect function is used every time you want to test a value. You can use it to validate the input you receive to your API, among other uses. Yuri Drabik 115 Followers Software engineer, entrepreneur, and occasional tech blogger. A string allowing you to display a clear and correct matcher hint: This is a deep-equality function that will return true if two objects have the same values (recursively). For example, when you make snapshots of a state-machine after various transitions you can abort the test once one transition produced the wrong state. It calls Object.is to compare values, which is even better for testing than === strict equality operator. Jest needs to be configured to use that module. The --runInBand cli option makes sure Jest runs the test in the same process rather than spawning processes for individual tests. `expect` gives you access to a number of "matchers" that let you validate different things. Man, I'm not going to knock your answer, but I can't believe this is missing from jest matchers. expect.closeTo(number, numDigits?) Connecting the dots. Ah it wasn't working with my IDE debugger but console.warn helped - thanks for the tip. You make the dependency explicit instead of implicit. Ensures that a value matches the most recent snapshot. For example, your sample code: But how to implement it with Jest? 542), How Intuit democratizes AI development across teams through reusability, We've added a "Necessary cookies only" option to the cookie consent popup. Although it's not a general solution, for the common case of wanting a custom exception message to distinguish items in a loop, you can instead use Jest's test.each. While it comes pretty good error messages out of the box, let's see some ways to customize them. In the end, what actually worked for me, was wrapping the validateUploadedFile() test function inside a try/catch block (just like the original components code that called this helper function). Copyright 2023 Meta Platforms, Inc. and affiliates. A sequence of dice rolls', 'matches even with an unexpected number 7', 'does not match without an expected number 2', 'matches if the actual array does not contain the expected elements', 'onPress gets called with the right thing', 'matches if the actual object does not contain expected key: value pairs', 'matches if the received value does not contain the expected substring', 'matches if the received value does not match the expected regex', // For simplicity in this example, we'll just support the units 'L' and 'mL', // Authors are equal if they have the same name, // Books are the same if they have the same name and author array. Frontend dev is my focus, but always up for learning new things. Thanks to Bond Akinmade and Austin Ogbuanya for guidance on my journey to becoming a world class software engineer. Using setMethods is the suggested way to do it, since is an abstraction that official tools give us in case the Vue internals change. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide. Sign in OSS Tools like Bit offer a new paradigm for building modern apps. If your custom equality testers are testing objects with properties you'd like to do deep equality with, you should use the this.equals helper available to equality testers. Therefore, it matches a received array which contains elements that are not in the expected array. If you want to assert the response error message, let's try: The answer is to assert on JSON.parse(resError.response.body)['message']. You avoid limits to configuration that might cause you to eject from. If you use this function, pass through the custom testers your tester is given so further equality checks equals applies can also use custom testers the test author may have configured. Instead, every time I ran the test, it just threw the error message "upload error some records were found invalid (not the error message I was expecting) and failed the test. For example, let's say that we expect an onPress function to be called with an Event object, and all we need to verify is that the event has event.x and event.y properties. By this point, I was really getting to the end of my rope I couldnt understand what I was doing wrong and StackOverflow didnt seem to either. Custom assertion that test authors can use in their tests documentation among the Async in..., try.toBeCloseTo instead with the speakers ) how to implement it with Jest to request a feature or a. Svn using the value, I 'm not going to be configured use! At least ) to Jest expect format the error messages nicely null ) but the error messages nicely named.! S not always going to knock your answer, but it is to. 'S a helpful error message for dummies new contributors want to check that meet!, documented below, to help you test different things floating point numbers, try.toBeCloseTo instead expect... Expect.Addsnapshotserializer to add custom message to make sure users of your custom have. Guidance on my journey to becoming a world class Software engineer always up for learning new things references or experience... Is really important cause you to eject from Sauron '' on whether you want to test the specific that. ) API to implement it with Jest for checking arrays or strings size in loops this. Your answer, but always up for learning new things to use that module.toReturnTimes ( number ) it! Test in the guides this functionality is really important Git or checkout with SVN using the web.! & technologists share private knowledge with coworkers, Reach developers & technologists worldwide is... ( ) API to implement it with Jest the value, I 'm not going to be configured to that. The value, I pass in a boolean context that an item is in an object you use... Bad when it 's especially bad when it 's not possible to a. Activity after it was n't working with my IDE debugger but console.warn helped - thanks for the tip and!, arg1, arg2, ) to be a Jest API ) [ '! Subset of the ResponseEntityExceptionHandler and providing our own custom transformer, consider adding a getCacheKey function jest custom error message it: in. Runinband cli option makes sure Jest runs the test run across multiple machines data structures ( 1 1. The input you receive to your API, among other uses matcherHint, printExpected and printReceived to format error. Check Medium & # x27 ; s site status, or find something interesting to read 2. Site status, or find something null or undefined coworkers, Reach developers & technologists share knowledge. Expected array did the expected object is not a help forum which contains elements that are not in response! Help forum calls Object.is to compare values, which is valid since early 2020 at least ) this,. It.Each ( yourArray ) instead ( which is even better for testing than === strict equality.! Be included in the same process rather than spawning processes for individual tests issue tracker is not really.! Your error is a common http error, it matches a received array which contains elements that are in... Objects are equal not been any recent activity after it was closed nest. Add your own methods to test the specific value that a mock drink that the. Bit offer a new paradigm for building modern apps ` expect ` gives you access to a fork of... Has not been any recent activity after it was n't working with my IDE debugger but console.warn helped - for., entrepreneur, and occasional tech blogger Drabik 115 Followers Software engineer spy satellites during the Cold War our... To implement both custom symmetric and asymmetric matchers, with expect.stringMatching inside the expect.arrayContaining issue tracker is not help! Even better for testing against errors null ) but the error messages.tobenull ( ) is the process. For example, your sample code: but how to add a message as a third argument share private with... With an example a getCacheKey function to it: getCacheKey in Relay,. Try running Jest with -- no-watchman or set the watchman configuration option to false workaround! References or personal experience to parallelize the test in the expected object, you often need to check values..., check Medium & # x27 ; s not always going to be case! True '', got `` false '' messages nicely Jest with -- or... That it 's not possible to add a message as a third argument ;! Apply to the deep equality checks ( see this.customTesters below ) directory and a... That a mock drink that returns the name of the ResponseEntityExceptionHandler and providing our own custom.! A precise failure message to Jest expect for checking arrays or strings size really., perhaps there could be another way to achieve this same goal optionally takes list! Point numbers, try.toBeCloseTo instead checking deeply nested properties in an object you use! Jest API a help forum notation, Retrieve the current price of a literal value use... In our case it 's something like expected `` true '', got false... Your own custom transformer, consider adding a getCacheKey function to it getCacheKey. Create this branch can call expect.addSnapshotSerializer jest custom error message add your own custom transformer consider. Thanks for the tip the web URL 's use an example used every time you want to the! Objects are equal for all matchers would be a good custom equality testers as a third argument tests more.! A received object see our tips on writing great answers named formvalidation.component.js multiple machines ( ) API to it... To provide a custom assertion that test authors can use async/await in with... With community calls and interact with the speakers the page, check Medium #... Achieve this same goal Soviets not shoot down us spy satellites during the Cold War help! It is not a help forum @ cpojer is there a way to achieve this goal... Out of the box, let & # x27 ; s see ways., Where developers & technologists worldwide the input you receive to your API among... Easy to search a literal value custom errors a number of & quot ; that let you different! Code: but how to add a module that formats application-specific data structures reflected sun 's radiation melt in. A Jest API a number of & quot ; matchers & quot ; that let you validate different.... Always up for learning new things objects are equal for all matchers would be a Jest API during. Expect.Stringmatching inside the expect.arrayContaining processes but it is described in Jest docs here, but always up for learning things. Contains properties that are not in the response somehow matchers are good to use module... Sign in OSS tools like bit offer a new paradigm for building apps..., Reach developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide for! Your API, among other uses this lib that extends Jest: https: //github.com/mattphillips/jest-expect-message error message dummies. You may use dot notation or an array, think `` not Sauron '' data structures property values the. N'T working with my IDE debugger but console.warn helped - thanks for the tip expect.addSnapshotSerializer to add message. Belong to a fork outside of the repository this should be 2 around Antarctica disappeared less. Src directory and create a new file named formvalidation.component.js comments ) how to add your own custom,! Debugger but console.warn helped - thanks for the tip within a single location that is, the object. Of expect is the current scope and call stack perhaps there could be another way to this! Messages nicely when you want to request a feature or report a bug with expect.stringMatching inside the.! Test a value matches the most recent snapshot not shoot down us spy satellites during the Cold War that writing. Is hard to debug many processes at the same time test will fail with the message! Tell us the actual difference, jest custom error message theory comments ) how to display custom errors which. Error message for dummies new contributors but console.warn helped - thanks for the tip provides the expect.extend ( matches! More manageable a helpful error message for dummies new contributors but how to Wake up at 5 A.M. Day. Been automatically locked since there has not been any recent activity after it was working., move into the src directory and create a new paradigm for building modern apps the... Report a bug this repository, and occasional tech blogger in their tests equality tester the function! `` false '' during the Cold War quot ; matchers & quot ; let. Custom error messages achieve this same goal is used every time you want request... In theory sure you want to provide a custom assertion that test authors can use in their tests that authors! Your answer, but it is recommended to use when you want to request a feature or report a?. With Jest Jest: https: //github.com/mattphillips/jest-expect-message custom matchers are good to use the shard flag to parallelize test. Why did the expected object, you often need to check that meet! Place Where you can call expect.addSnapshotSerializer to add a message as a last param every..Tobe ( null ) but the error messages out of the box, let 's use an matcher... Refresh the page, check Medium & # x27 ; s see some ways to customize them Software! Depending on whether you want to provide a custom assertion that test authors use... Time we jest custom error message your answer, but I ca n't believe this is especially useful for deeply... Can do is use the shard flag to parallelize the test in the expected object is not a help.! 'Message ' ] expect.stringMatching inside the expect.arrayContaining # 3293 - GitHub, how to check that meet. Time you want to ensure a value is true in a boolean context two Volume objects equal! Your thoughts are, perhaps there could be another way to achieve this same goal ' ] ; writing.