I want to create a unit test for an attributed string. Here is my code
func setupMyLabel() {
myLabel.isHidden = false
let attributes = [NSAttributedString.Key.font: Style.FontBook.bold,
NSAttributedString.Key.foregroundColor: Theme.brand]
if userConnected {
myLabel.attributedText = NSAttributedString(string: "myLabel_longText".localized, attributes: nil)
.replacingFields(["1": (replacement: "myLabel_firstPart".localized,
attributes: attributes)])
} else {
myLabel.text = NSLocalizedString("myLabel_shortext", comment: "myLabel_shortext")
}
}
Here my unit test that I wrote to test when the user is not connected, since the label would contain only text
import Nimble
import Quick
import Mockingjay
context("When user is not connected"){
it("should display my label, and label should contain shortText string"){
disconnectUser()
vc.setupMyLabel()
expect(vc.myLabel.isHidden).to(beFalse())
expect(vc.myLabel.text).to(equal(String.localizedStringWithFormat("myLabel_shortext".localized, "")))
}
}
but I'm a little bit stuck to write the unit test for the attributed when the user is connected !
context("When user is connected"){
it("should display my label, and label should contain longText string"){
connectUser()
vc.setupMyLabel()
expect(vc.myLabel.isHidden).to(beFalse())
expect(vc.myLabel.attributedText).to(equal( .... ?? ))
}
}