breautek commented on issue #695: (iOS) Added Semver to version comparison checks. URL: https://github.com/apache/cordova-ios/pull/695#issuecomment-545033934 No problem, we all start somewhere. I've only began unit testing my code earlier this year, and it's an important piece of knowledge when working on larger projects. I'll walk you through this one, please keep notes ;) you can run `npm test` to launch both eslint and the unit tests. This is how you can ensure that everything is good before you push. Unit test primarily focus is to ensure that given a certain input, you expect a certain output. We use jasmine for unit testing, so you can find the documentation for jasmine at https://jasmine.github.io/pages/docs_home.html Use the appropriate API version, not all platforms/plugins use a consistent jasmine version sometimes. Generally speaking, a unit test tests a function, or something, and when given a certain set of inputs, it tests the output and expect it to be a certain value. e.g.: ```javascript var add = function(a,b) { return a + b; } it("should add two numbers", function() { var result = add(2, 5); expect(result).toBe(7); }); ``` This is a very simple example, the unit tests in cordova are obviously a bit more complex, but take your time, they'll have a pattern and should be pretty understandable. If a unit test fails, it generally means that function output or behaviour has changed. Perhaps it is throwing an error, or it's output is returning something completely different than expected (which could signal a breaking change). So ideally, the code should pass the tests without modifying the existing tests. However sometimes, modifying the tests is necessary, depending on the situation. In your case, the test is failing because it is using asynchronous function, and the `done()` method is never being called. It is testing the version `v1.0.0` and is expecting `checkTool` to throw an error. ``` checkTool('node', 'v1.0.0').catch((error) => { expect(error).toEqual('Version should contain only numbers and dots'); done(); }); ``` You're PR makes it so it can handle version string `v1.0.0`, so now `checkTool` is not throwing an error when testing `v1.0.0`, thus the `.catch` statement is never being called. So in this case, it should be safe to modify the existing unit test because `v1.0.0` is something cordova can now successfully parse and handle. So we can probably change this test to test for something more outlandish, say `a.b.c`, or maybe `1.2.a`
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
