I have heard that chilli peppers and coffee evolved to contain toxic chemicals which help to protect them from predators. And recently I learned that star anise, liquorice and aniseed are not actually related plants, but each independently developed the ability to produce anethole, which can also deter predators.
However humans have evolved resistance so they can ingest all these substances, and tend to enjoy their extreme flavours. Some more examples are onions, garlic, peppercorns and tea (for its stimulative effect rather than for its flavour).
It made me wonder:
Did the active ingredient in chocolate also evolve to deter predators?
And I am also curious, are there any other foods which I haven't mentioned that humans also enjoy due to their toxic or deterrent components? (I'm thinking more about flavour than psychoactive effects here, as I know there are many examples of the latter.)