1

I am trying to test (with Jasmine) validation of a description field (which is a knockout observable) with max length of 1000 characters; What I usually do is expect(model.description().length).toBe(1000); to prove that my string is of the desired length. Is there any way to mock it somehow without the need to actually write a string of 1000 chars long?

koninos
  • 4,969
  • 5
  • 28
  • 47

1 Answers1

1

If you are intent on mocking the object and just want to use the length property and nothing else then as mentioned by @GOTO-0, you can just create an object with that property set like this: { length: 1000 }.

However, it seems easier to just create a string that is that length. This could help as if some of the code changes to require an actual string elsewhere, the test will still be valid rather than you having to start mocking other methods and properties of a string. See this question for discussions on how to do that best: Create a string of variable length, filled with a repeated character

Community
  • 1
  • 1
TomDoesCode
  • 3,580
  • 2
  • 18
  • 34