All components go through several test campaigns on the ground, while iterating on the design to address issues. These campaigns take months/years. That's why changes are stacked into "blocks", which are the equivalent of rocket versions. Each block must be certified by the Air Force and NASA to be deemed worthy of flying their payloads.
So while you're right that SpaceX doesn't typically do this sort of thing, NASA did pay them to fly an untested nozzle design.
1. https://en.wikipedia.org/wiki/SpaceX_COTS_Demo_Flight_1
2. See the section titled "Snipping the nozzle" at https://arstechnica.com/science/2020/06/forget-dragon-the-fa...