Chapter 11: Testing categories

When i copied the categories tests and try to run them I get the error :

failed - typeMismatch(Swift.String, Swift.DecodingError.Context(codingPath: [ModelCodingKey(stringValue: “name”, intValue: nil)], debugDescription: “Could not decode property”, underlyingError: Optional(Swift.DecodingError.keyNotFound(ModelCodingKey(stringValue: “name”, intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: “No value associated with key ModelCodingKey(stringValue: “name”, intValue: nil) (“name”).”, underlyingError: nil)))))

on the testGettingASingleCategoryFromTheAPI().

i have tried to solve the error by decoding the category with App.Category.self but the error still stays. Anyone have any ideas ?

Thanks for a great book.

solved it. pls remove this.

@hvaftrudner, how did you solve the issue?

@hvaftrudner how did you solve this issue? Can you pls share with us?

It’s likely the JSON you’re sending doesn’t match what you’re trying to decode

@mobven, in my case the problem was I failed to include the trailing ‘/’ in categoriesURI. I had:

let categoriesURI = "/api/categories"

instead of

let categoriesURI = "/api/categories/"

1 Like

I did it but nothing changed. Thank you by the way.

I had made a typo in the CategoriesController that didn’t recognize the call because of the typo.
Be sure to update both controllers and the migration correctly.