How to use testMatchNSErrorPositive method of MatchErrorTest class

Best Nimble code snippet using MatchErrorTest.testMatchNSErrorPositive

Run Nimble automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

MatchErrorTest.swift

Source: MatchErrorTest.swift Github

copy
1import Foundation
2import XCTest
3import Nimble
4
5final class MatchErrorTest: XCTestCase, XCTestCaseProvider {
6    static var allTests: [(String, (MatchErrorTest) -> () throws -> Void)] {
7        return [
8            ("testMatchErrorPositive", testMatchErrorPositive),
9            ("testMatchErrorNegative", testMatchErrorNegative),
10            ("testMatchNSErrorPositive", testMatchNSErrorPositive),
11            ("testMatchNSErrorNegative", testMatchNSErrorNegative),
12            ("testMatchPositiveMessage", testMatchPositiveMessage),
13            ("testMatchNegativeMessage", testMatchNegativeMessage),
14            ("testDoesNotMatchNils", testDoesNotMatchNils),
15        ]
16    }
17
18    func testMatchErrorPositive() {
19        expect(NimbleError.laugh).to(matchError(NimbleError.laugh))
20        expect(NimbleError.laugh).to(matchError(NimbleError.self))
21        expect(EquatableError.parameterized(x: 1)).to(matchError(EquatableError.parameterized(x: 1)))
22
23        expect(NimbleError.laugh as Error).to(matchError(NimbleError.laugh))
24    }
25
26    func testMatchErrorNegative() {
27        expect(NimbleError.laugh).toNot(matchError(NimbleError.cry))
28        expect(NimbleError.laugh as Error).toNot(matchError(NimbleError.cry))
29        expect(NimbleError.laugh).toNot(matchError(EquatableError.self))
30    }
31
32    func testMatchNSErrorPositive() {
33        let error1 = NSError(domain: "err", code: 0, userInfo: nil)
34        let error2 = NSError(domain: "err", code: 0, userInfo: nil)
35
36        expect(error1).to(matchError(error2))
37    }
38
39    func testMatchNSErrorNegative() {
40        let error1 = NSError(domain: "err", code: 0, userInfo: nil)
41        let error2 = NSError(domain: "err", code: 1, userInfo: nil)
42
43        expect(error1).toNot(matchError(error2))
44    }
45
46    func testMatchPositiveMessage() {
47        failsWithErrorMessage("expected to match error <parameterized(2)>, got <parameterized(1)>") {
48            expect(EquatableError.parameterized(x: 1)).to(matchError(EquatableError.parameterized(x: 2)))
49        }
50        failsWithErrorMessage("expected to match error <cry>, got <laugh>") {
51            expect(NimbleError.laugh).to(matchError(NimbleError.cry))
52        }
53        failsWithErrorMessage("expected to match error <code=1>, got <code=0>") {
54            expect(CustomDebugStringConvertibleError.a).to(matchError(CustomDebugStringConvertibleError.b))
55        }
56
57        failsWithErrorMessage("expected to match error <Error Domain=err Code=1 \"(null)\">, got <Error Domain=err Code=0 \"(null)\">") {
58            let error1 = NSError(domain: "err", code: 0, userInfo: nil)
59            let error2 = NSError(domain: "err", code: 1, userInfo: nil)
60            expect(error1).to(matchError(error2))
61        }
62    }
63
64    func testMatchNegativeMessage() {
65        failsWithErrorMessage("expected to not match error <laugh>, got <laugh>") {
66            expect(NimbleError.laugh).toNot(matchError(NimbleError.laugh))
67        }
68
69        failsWithErrorMessage("expected to match error from type <EquatableError>, got <laugh>") {
70            expect(NimbleError.laugh).to(matchError(EquatableError.self))
71        }
72    }
73
74    func testDoesNotMatchNils() {
75        failsWithErrorMessageForNil("expected to match error <laugh>, got no error") {
76            expect(nil as Error?).to(matchError(NimbleError.laugh))
77        }
78
79        failsWithErrorMessageForNil("expected to not match error <laugh>, got no error") {
80            expect(nil as Error?).toNot(matchError(NimbleError.laugh))
81        }
82    }
83}
84
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger testMatchNSErrorPositive code on LambdaTest Cloud Grid

Execute automation tests with testMatchNSErrorPositive on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)