But it doesn't only happen in this industry: my niece is a graphic designer & has been asked to provide samples of her work on projects ... to the interviewer's specification. She's done it, because she really needed the work, but felt terribly taken advantage of, and I'd agree: it's predatory.
I have the luxury of telling people that, no, I won't take their 1) IQ test, 2) Personality Test, or 3) their Coding Challenges. Not everybody does, certainly.
The appropriate thing to do is to either state up front that you'd need to be compensated for your time, or acknowledge that you're giving away work as a way to possibly get in the door & just write the best solution you can write - not leaving it incomplete, necessarily, either, as that is a sort-of halfway position that makes you look bad.